Skip to content

Commit

Permalink
Add i18n support for JS.
Browse files Browse the repository at this point in the history
  • Loading branch information
fumikito committed Dec 4, 2018
1 parent 4bd16f6 commit b9c3920
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 54 deletions.
5 changes: 3 additions & 2 deletions assets/js/src/definition-description.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const { registerBlockType } = wp.blocks;
const { RichText } = wp.editor;
const { __ } = wp.i18n;


/* global YomiganaDd: false */

registerBlockType( 'wp-yomigana/description', {

title: YomiganaDd.label,
title: __( 'Description', 'wp-yomigana' ),

icon: (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240"><path d="M28.71,33.65V21.49H71.27V38.21h-3ZM71.27,208.44v16.72H28.71V213l39.52-4.56ZM57.59,115.73c0-31.31,0-62.93-.91-94.24H85.86C85,52.19,85,83.81,85,115.73v11.55c0,35,0,66.57.91,97.88H56.68c.91-30.7.91-62.32.91-97.88Zm13.68,95.45h39.21c47.73,0,73.87-32.23,73.87-87.55,0-57.45-26.14-88.16-71.13-88.16H71.27v-14h47.12c57.76,0,97.88,35.87,97.88,102.14,0,65.66-45,101.53-104,101.53h-41Z"/></svg>
Expand Down
6 changes: 3 additions & 3 deletions assets/js/src/definition-list.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const { registerBlockType } = wp.blocks;
const { InnerBlocks } = wp.editor;

/* global YomiganaDl: false */
const { __ } = wp.i18n;

registerBlockType( 'wp-yomigana/dl', {

title: YomiganaDl.label,
title: __( 'Definition List', 'wp-yomigana' ),

icon: (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240">
Expand Down Expand Up @@ -38,4 +37,5 @@ registerBlockType( 'wp-yomigana/dl', {
</dl>
)
}

} );
6 changes: 3 additions & 3 deletions assets/js/src/definition-term.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { registerBlockType } = wp.blocks;
const { RichText } = wp.editor;
const { RichText } = wp.editor;
const { __ } = wp.i18n;

/* global YomiganaDt: false */

registerBlockType( 'wp-yomigana/term', {

title: YomiganaDt.label,
title: __( 'Term', 'wp-yomigana' ),

icon: (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240"><title>block-icons</title><path d="M49.46,38.07,62.65,23.41,53.27,75.59H36.85L39.2,23.41h160l2.35,52.18H185.17l-9.38-52.18L189,38.07Zm72.69,165.61,41,4.4v11.73H75.25V208.08l41-4.4ZM106,114.28c0-30.19,0-60.67-.88-90.87h28.14c-.88,29.61-.88,60.09-.88,90.87v14.66c0,30.19,0,60.67.88,90.87H105.15c.88-29.61.88-60.09.88-90.87Z"/></svg>
Expand Down
Binary file modified i18n/wp-yomigana-ja.mo
Binary file not shown.
43 changes: 28 additions & 15 deletions i18n/wp-yomigana-ja.po
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2018-03-14 15:41+0900\n"
"PO-Revision-Date: 2018-03-15 02:16+0900\n"
"POT-Creation-Date: 2018-12-04 18:44+0900\n"
"PO-Revision-Date: 2018-12-04 19:51+0900\n"
"Last-Translator: Takahashi Fumiki <takahashi.fumiki@hametuha.co.jp>\n"
"Language-Team: \n"
"Language: ja\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.4\n"
"X-Generator: Poedit 2.2\n"
"X-Poedit-Basepath: .\n"
"Plural-Forms: nplurals=1; plural=0;\n"

Expand All @@ -29,43 +29,44 @@ msgstr "ルビ設定"
msgid "Setting"
msgstr "設定"

#: src/Hametuha/Yomigana/Bootstrap.php:92
#: src/Hametuha/Yomigana/Bootstrap.php:93 assets/js/src/definition-list.jsx:7
msgid "Definition List"
msgstr "定義リスト"

#: src/Hametuha/Yomigana/Bootstrap.php:93
#: src/Hametuha/Yomigana/Bootstrap.php:94
msgid "Apply / Strip"
msgstr "適用 / 解除"

#: src/Hametuha/Yomigana/Bootstrap.php:94
#: src/Hametuha/Yomigana/Bootstrap.php:95
msgid "Switch term and definition"
msgstr "用語と定義を切り替え"

#: src/Hametuha/Yomigana/Bootstrap.php:95
#: src/Hametuha/Yomigana/Bootstrap.php:96
msgid "Inline Quote"
msgstr "インライン引用"

#: src/Hametuha/Yomigana/Bootstrap.php:97
#: src/Hametuha/Yomigana/Bootstrap.php:98
msgid "Annotation"
msgstr "注釈"

#: src/Hametuha/Yomigana/Bootstrap.php:98
#: src/Hametuha/Yomigana/Bootstrap.php:99
msgid "Cite"
msgstr "引用元"

#: src/Hametuha/Yomigana/Bootstrap.php:99 templates/ruby.php:14
#: src/Hametuha/Yomigana/Bootstrap.php:100 templates/ruby.php:15
#: assets/js/src/wp-yomigana-gutenberg.jsx:16
msgid "Ruby"
msgstr "ルビ"

#: src/Hametuha/Yomigana/Bootstrap.php:102
#: src/Hametuha/Yomigana/Bootstrap.php:103
msgid "Cancel"
msgstr "キャンセル"

#: src/Hametuha/Yomigana/Bootstrap.php:103
#: src/Hametuha/Yomigana/Bootstrap.php:104
msgid "OK"
msgstr "OK"

#: src/Hametuha/Yomigana/Bootstrap.php:104
#: src/Hametuha/Yomigana/Bootstrap.php:105
msgid "Delete"
msgstr "削除"

Expand All @@ -81,11 +82,11 @@ msgstr "引用文"
msgid "Source / URL"
msgstr "引用元 / URL"

#: templates/ruby.php:5
#: templates/ruby.php:6
msgid "Enter ruby annotation."
msgstr "ルビを入力してください。"

#: templates/ruby.php:8
#: templates/ruby.php:9
msgid "Parent String"
msgstr "親文字"

Expand Down Expand Up @@ -125,6 +126,18 @@ msgstr "WP-Yomigana は PHP %1$s 以上が必須ですが、ご利用のPHPは %
msgid "WP-Yomigana's auto load file %s is not found."
msgstr "WP-Yomigana の オートロードファイル %s が見つかりません。"

#: assets/js/src/definition-description.jsx:8
msgid "Description"
msgstr "説明"

#: assets/js/src/definition-term.jsx:7
msgid "Term"
msgstr "用語"

#: assets/js/src/wp-yomigana-gutenberg.jsx:28
msgid "Span"
msgstr "スパン"

#. Plugin Name of the plugin/theme
msgid "WP-Yomigana"
msgstr "WP-Yomigana"
Expand Down
48 changes: 30 additions & 18 deletions i18n/wp-yomigana.pot
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ msgid ""
msgstr ""
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
"Project-Id-Version: WP-Yomigana\n"
"POT-Creation-Date: 2018-03-14 15:41+0900\n"
"POT-Creation-Date: 2018-12-04 19:51+0900\n"
"PO-Revision-Date: 2018-03-13 02:41+0900\n"
"Last-Translator: Takahashi Fumiki <takahashi.fumiki@hametuha.co.jp>\n"
"Language-Team: Takahashi Fumiki <takahashi.fumiki@hametuha.co.jp>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.4\n"
"X-Generator: Poedit 2.2\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-Flags-xgettext: --add-comments=translators:\n"
"X-Poedit-WPHeader: wp-yomigana.php\n"
Expand All @@ -19,10 +19,9 @@ msgstr ""
"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;"
"_n_noop:1,2;_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: *.js\n"
"X-Poedit-SearchPathExcluded-1: assets\n"
"X-Poedit-SearchPathExcluded-2: node_modules\n"
"X-Poedit-SearchPathExcluded-3: vendor\n"
"X-Poedit-SearchPathExcluded-0: node_modules\n"
"X-Poedit-SearchPathExcluded-1: vendor\n"
"X-Poedit-SearchPathExcluded-2: assets/js/dist\n"

#: src/Hametuha/Yomigana/Admin.php:48
msgid "Option has been updated."
Expand All @@ -40,43 +39,44 @@ msgstr ""
msgid "Setting"
msgstr ""

#: src/Hametuha/Yomigana/Bootstrap.php:92
#: src/Hametuha/Yomigana/Bootstrap.php:93 assets/js/src/definition-list.jsx:7
msgid "Definition List"
msgstr ""

#: src/Hametuha/Yomigana/Bootstrap.php:93
#: src/Hametuha/Yomigana/Bootstrap.php:94
msgid "Apply / Strip"
msgstr ""

#: src/Hametuha/Yomigana/Bootstrap.php:94
#: src/Hametuha/Yomigana/Bootstrap.php:95
msgid "Switch term and definition"
msgstr ""

#: src/Hametuha/Yomigana/Bootstrap.php:95
#: src/Hametuha/Yomigana/Bootstrap.php:96
msgid "Inline Quote"
msgstr ""

#: src/Hametuha/Yomigana/Bootstrap.php:97
#: src/Hametuha/Yomigana/Bootstrap.php:98
msgid "Annotation"
msgstr ""

#: src/Hametuha/Yomigana/Bootstrap.php:98
#: src/Hametuha/Yomigana/Bootstrap.php:99
msgid "Cite"
msgstr ""

#: src/Hametuha/Yomigana/Bootstrap.php:99 templates/ruby.php:14
#: src/Hametuha/Yomigana/Bootstrap.php:100 templates/ruby.php:15
#: assets/js/src/wp-yomigana-gutenberg.jsx:16
msgid "Ruby"
msgstr ""

#: src/Hametuha/Yomigana/Bootstrap.php:102
#: src/Hametuha/Yomigana/Bootstrap.php:103
msgid "Cancel"
msgstr ""

#: src/Hametuha/Yomigana/Bootstrap.php:103
#: src/Hametuha/Yomigana/Bootstrap.php:104
msgid "OK"
msgstr ""

#: src/Hametuha/Yomigana/Bootstrap.php:104
#: src/Hametuha/Yomigana/Bootstrap.php:105
msgid "Delete"
msgstr ""

Expand All @@ -92,11 +92,11 @@ msgstr ""
msgid "Source / URL"
msgstr ""

#: templates/ruby.php:5
#: templates/ruby.php:6
msgid "Enter ruby annotation."
msgstr ""

#: templates/ruby.php:8
#: templates/ruby.php:9
msgid "Parent String"
msgstr ""

Expand Down Expand Up @@ -136,6 +136,18 @@ msgstr ""
msgid "WP-Yomigana's auto load file %s is not found."
msgstr ""

#: assets/js/src/definition-description.jsx:8
msgid "Description"
msgstr ""

#: assets/js/src/definition-term.jsx:7
msgid "Term"
msgstr ""

#: assets/js/src/wp-yomigana-gutenberg.jsx:28
msgid "Span"
msgstr ""

#. Plugin Name of the plugin/theme
msgid "WP-Yomigana"
msgstr ""
Expand Down
30 changes: 17 additions & 13 deletions src/Hametuha/Yomigana/Gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,24 @@ protected function __construct() {
*/
public function register_script() {
// Register DL.
wp_register_script( 'wp-yomigana-dl', $this->assets . '/js/dist/definition-list.js', [ 'wp-blocks', 'wp-editor' ], self::VERSION, true );
wp_localize_script( 'wp-yomigana-dl', 'YomiganaDl', [
'label' => __( 'Definition List', 'wp-yomigana' ),
] );
wp_register_style( 'wp-yomigana-dl', $this->assets . '/css/editor-dl.css', [], self::VERSION );
wp_register_script( 'wp-yomigana-dl', $this->assets . '/js/dist/definition-list.js', [ 'wp-blocks', 'wp-editor', 'wp-i18n' ], self::VERSION, true );
wp_register_style( 'wp-yomigana-dl', $this->assets . '/css/editor-dl.css', [ 'wp-blocks' ], self::VERSION );
// Register dt
wp_register_script( 'wp-yomigana-dt', $this->assets . '/js/dist/definition-term.js', [ 'wp-blocks', 'wp-editor' ], self::VERSION, true );
wp_localize_script( 'wp-yomigana-dt', 'YomiganaDt', [
'label' => __( 'Term', 'wp-yomigana' ),
] );
wp_register_script( 'wp-yomigana-dd', $this->assets . '/js/dist/definition-description.js', [ 'wp-blocks', 'wp-editor' ], self::VERSION, true );
wp_localize_script( 'wp-yomigana-dd', 'YomiganaDd', [
'label' => __( 'Description', 'wp-yomigana' ),
] );
wp_register_script( 'wp-yomigana-dt', $this->assets . '/js/dist/definition-term.js', [ 'wp-yomigana-dl' ], self::VERSION, true );
// Register dd
wp_register_script( 'wp-yomigana-dd', $this->assets . '/js/dist/definition-description.js', [ 'wp-yomigana-dl' ], self::VERSION, true );
// Register translation.
if ( function_exists( 'gutenberg_get_jed_locale_data' ) ) {
$json = json_encode( gutenberg_get_jed_locale_data( 'wp-yomigana' ) );
wp_add_inline_script(
'wp-yomigana-dl',
sprintf( 'wp.i18n.setLocaleData( %s, "wp-yomigana" );', $json ),
'before'
);
}
if ( function_exists( 'wp_set_script_translations' ) ) {
wp_set_script_translations( 'wp-yomigana-dl', 'wp-yomigana' );
}
}

/**
Expand Down

0 comments on commit b9c3920

Please sign in to comment.