From ee1154b64d556c36d1fc27eec3fb7ce938528573 Mon Sep 17 00:00:00 2001 From: Maxime BERNARD-JACQUET Date: Mon, 10 Dec 2018 18:44:20 +0100 Subject: [PATCH 1/2] Setup i18n with textdomain + set script translations --- packages/cgb-scripts/template/src/init.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/cgb-scripts/template/src/init.php b/packages/cgb-scripts/template/src/init.php index 3df3b71e..0464c435 100644 --- a/packages/cgb-scripts/template/src/init.php +++ b/packages/cgb-scripts/template/src/init.php @@ -51,6 +51,13 @@ function <% blockNamePHPLower %>_cgb_editor_assets() { // phpcs:ignore true // Enqueue the script in the footer. ); + // Send translations to JS files + // Param 1: JS handle + // Param 2: textdomain + if ( function_exists('wp_set_script_translations') ) { + wp_set_script_translations( '<% blockNamePHPLower %>-cgb-block-js', '<% blockNamePHPLower %>' ); + } + // Styles. wp_enqueue_style( '<% blockNamePHPLower %>-cgb-block-editor-css', // Handle. @@ -62,3 +69,12 @@ function <% blockNamePHPLower %>_cgb_editor_assets() { // phpcs:ignore // Hook: Editor assets. add_action( 'enqueue_block_editor_assets', '<% blockNamePHPLower %>_cgb_editor_assets' ); + + +/** + * Set a Textdomain for i18n + */ +function <% blockNamePHPLower %>_load_textdomain() { + load_plugin_textdomain( '<% blockNamePHPLower %>' ); +} +add_action( 'plugins_loaded', '<% blockNamePHPLower %>_load_textdomain' ); \ No newline at end of file From cd05e7267bdd5772273d8f707e0763772ff8d147 Mon Sep 17 00:00:00 2001 From: Maxime BERNARD-JACQUET Date: Mon, 10 Dec 2018 18:51:00 +0100 Subject: [PATCH 2/2] Fix auto generated names using blockName instead of blockNamePHPLower --- packages/cgb-scripts/template/src/init.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cgb-scripts/template/src/init.php b/packages/cgb-scripts/template/src/init.php index 0464c435..0a06c5e3 100644 --- a/packages/cgb-scripts/template/src/init.php +++ b/packages/cgb-scripts/template/src/init.php @@ -55,7 +55,7 @@ function <% blockNamePHPLower %>_cgb_editor_assets() { // phpcs:ignore // Param 1: JS handle // Param 2: textdomain if ( function_exists('wp_set_script_translations') ) { - wp_set_script_translations( '<% blockNamePHPLower %>-cgb-block-js', '<% blockNamePHPLower %>' ); + wp_set_script_translations( '<% blockName % >-cgb-block-js', '<% blockName % >' ); } // Styles. @@ -75,6 +75,6 @@ function <% blockNamePHPLower %>_cgb_editor_assets() { // phpcs:ignore * Set a Textdomain for i18n */ function <% blockNamePHPLower %>_load_textdomain() { - load_plugin_textdomain( '<% blockNamePHPLower %>' ); + load_plugin_textdomain( '<% blockName % >' ); } add_action( 'plugins_loaded', '<% blockNamePHPLower %>_load_textdomain' ); \ No newline at end of file