Skip to content

Commit

Permalink
Add/i18n example (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
nosolosw authored Mar 11, 2019
1 parent 503e934 commit 21b561b
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 0 deletions.
24 changes: 24 additions & 0 deletions i18n/block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { __ } = wp.i18n;
const el = wp.element.createElement;
const { registerBlockType } = wp.blocks;

registerBlockType( 'myguten/simple', {
title: __('Simple Block', 'myguten'),
category: 'widgets',

edit: function() {
return el(
'p',
{ style: { color:'red'}, },
__('Hello World', 'myguten')
);
},

save: function() {
return el(
'p',
{ style: { color:'red'}, },
__('Hello World', 'myguten')
);
}
});
22 changes: 22 additions & 0 deletions i18n/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Plugin Name: Myguten Plugin
* Text Domain: myguten
*/
function myguten_block_init() {
wp_register_script(
'myguten-script',
plugins_url( 'block.js', __FILE__ ),
array( 'wp-blocks', 'wp-element', 'wp-i18n' )
);

register_block_type( 'myguten/simple', array(
'editor_script' => 'myguten-script',
) );
}
add_action( 'init', 'myguten_block_init' );

function myguten_set_script_translations() {
wp_set_script_translations( 'myguten-script', 'myguten', plugin_dir_path( __FILE__ ) . 'languages' );
}
add_action( 'init', 'myguten_set_script_translations' );
20 changes: 20 additions & 0 deletions i18n/languages/myguten-eo-myguten-script.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"domain": "messages",
"locale_data": {
"messages": {
"": {
"domain": "messages",
"lang": "eo"
},
"Scratch Plugin": [
"Scratch kromprogrameto"
],
"Simple Block": [
"Simpla bloko"
],
"Hello World": [
"Howdy mundo"
]
}
}
}
28 changes: 28 additions & 0 deletions i18n/languages/myguten-eo.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2019
# This file is distributed under the same license as the Scratch Plugin plugin.
msgid ""
msgstr ""
"Project-Id-Version: Scratch Plugin\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/scratch\n"
"Last-Translator: Marcus Kazmierczak <[email protected]>\n"
"Language-Team: Esperanto <[email protected]>\n"
"Language: eo\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2019-02-18T07:20:46-08:00\n"
"PO-Revision-Date: 2019-02-18 08:16-0800\n"
"X-Generator: Poedit 2.2.1\n"
"X-Domain: myguten\n"

#. Plugin Name of the plugin
msgid "Scratch Plugin"
msgstr "Scratch kromprogrameto"

#: block.js:6
msgid "Simple Block"
msgstr "Simpla bloko"

#: block.js:13 block.js:21
msgid "Hello World"
msgstr "Saltuon mundo"
28 changes: 28 additions & 0 deletions i18n/languages/myguten.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2019
# This file is distributed under the same license as the Myguten Plugin plugin.
msgid ""
msgstr ""
"Project-Id-Version: Myguten Plugin\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/i18n\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2019-03-11T11:22:59+01:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.1.0\n"
"X-Domain: myguten\n"

#. Plugin Name of the plugin
msgid "Myguten Plugin"
msgstr ""

#: block.js:6
msgid "Simple Block"
msgstr ""

#: block.js:13
#: block.js:21
msgid "Hello World"
msgstr ""
19 changes: 19 additions & 0 deletions i18n/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "myguten-plugin",
"version": "1.0.0",
"description": "Example WordPress plugin to demonstrate how to work with i18n.",
"main": "block.js",
"repository": {
"type": "git",
"url": "git+https://github.com/nosolosw/blocksettingsmenu-plugin.git"
},
"author": "",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/nosolosw/blocksettingsmenu-plugin/issues"
},
"homepage": "https://github.com/nosolosw/blocksettingsmenu-plugin#readme",
"devDependencies": {
"po2json": "1.0.0-alpha"
}
}

0 comments on commit 21b561b

Please sign in to comment.