From 4331503c2235dc32889b41e3c68b6ebdb0e76373 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Tue, 12 Jan 2021 18:15:13 +0100 Subject: [PATCH 1/5] Blocks: Add i18n support to register_block_type_from_metadata --- package-lock.json | 2 +- src/wp-includes/blocks.php | 40 +++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index b8c08e97ed2d7..0c6a1c3e27e98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6032,7 +6032,7 @@ }, "browserify-aes": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", + "resolved": "http://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", "dev": true, "requires": { diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 1b5427340f433..3b2a57ea04b26 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -227,9 +227,47 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { 'apiVersion' => 'api_version', ); + $textdomain = isset( $metadata['textdomain'] ) ? $metadata['textdomain'] : 'default'; + foreach ( $property_mappings as $key => $mapped_key ) { if ( isset( $metadata[ $key ] ) ) { - $settings[ $mapped_key ] = $metadata[ $key ]; + $value = $metadata[ $key ]; + switch ( $key ) { + case 'title': + case 'description': + // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain + $settings[ $mapped_key ] = translate( $value, $textdomain ); + break; + case 'keywords': + $settings[ $mapped_key ] = array(); + if ( ! is_array( $value ) ) { + continue 2; + } + + foreach ( $value as $keyword ) { + // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain + $settings[ $mapped_key ][] = translate( $keyword, $textdomain ); + } + + break; + case 'styles': + $settings[ $mapped_key ] = array(); + if ( ! is_array( $value ) ) { + continue 2; + } + + foreach ( $value as $style ) { + if ( ! empty( $style['label'] ) ) { + // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain + $style['label'] = translate( $style['label'], $textdomain ); + } + $settings[ $mapped_key ][] = $style; + } + + break; + default: + $settings[ $mapped_key ] = $value; + } } } From cdc6950c088c31d4833668e92ba0a52a62d3325b Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Wed, 13 Jan 2021 13:25:36 +0100 Subject: [PATCH 2/5] Add unit tests covering i18n support for block.json --- .../data/blocks/internationalized/block.json | 21 ++++++++ .../blocks/notice}/block.asset.php | 0 .../fixtures => data/blocks/notice}/block.css | 0 .../fixtures => data/blocks/notice}/block.js | 0 .../blocks/notice}/block.json | 2 +- tests/phpunit/tests/blocks/register.php | 54 ++++++++++++++++--- 6 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 tests/phpunit/data/blocks/internationalized/block.json rename tests/phpunit/{tests/blocks/fixtures => data/blocks/notice}/block.asset.php (100%) rename tests/phpunit/{tests/blocks/fixtures => data/blocks/notice}/block.css (100%) rename tests/phpunit/{tests/blocks/fixtures => data/blocks/notice}/block.js (100%) rename tests/phpunit/{tests/blocks/fixtures => data/blocks/notice}/block.json (96%) diff --git a/tests/phpunit/data/blocks/internationalized/block.json b/tests/phpunit/data/blocks/internationalized/block.json new file mode 100644 index 0000000000000..b039899c33138 --- /dev/null +++ b/tests/phpunit/data/blocks/internationalized/block.json @@ -0,0 +1,21 @@ +{ + "name": "tests/internationalized", + "title": "This is a dummy plugin", + "description": "This is a dummy plugin", + "keywords": [ + "alert", + "This is a dummy plugin" + ], + "styles": [ + { + "name": "default", + "label": "Default", + "isDefault": true + }, + { + "name": "other", + "label": "This is a dummy plugin" + } + ], + "textdomain": "internationalized" +} diff --git a/tests/phpunit/tests/blocks/fixtures/block.asset.php b/tests/phpunit/data/blocks/notice/block.asset.php similarity index 100% rename from tests/phpunit/tests/blocks/fixtures/block.asset.php rename to tests/phpunit/data/blocks/notice/block.asset.php diff --git a/tests/phpunit/tests/blocks/fixtures/block.css b/tests/phpunit/data/blocks/notice/block.css similarity index 100% rename from tests/phpunit/tests/blocks/fixtures/block.css rename to tests/phpunit/data/blocks/notice/block.css diff --git a/tests/phpunit/tests/blocks/fixtures/block.js b/tests/phpunit/data/blocks/notice/block.js similarity index 100% rename from tests/phpunit/tests/blocks/fixtures/block.js rename to tests/phpunit/data/blocks/notice/block.js diff --git a/tests/phpunit/tests/blocks/fixtures/block.json b/tests/phpunit/data/blocks/notice/block.json similarity index 96% rename from tests/phpunit/tests/blocks/fixtures/block.json rename to tests/phpunit/data/blocks/notice/block.json index 4cd2b4cd6912b..ed60fd844021f 100644 --- a/tests/phpunit/tests/blocks/fixtures/block.json +++ b/tests/phpunit/data/blocks/notice/block.json @@ -18,7 +18,7 @@ "alert", "message" ], - "textDomain": "my-plugin", + "textdomain": "my-plugin", "attributes": { "message": { "type": "string", diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 7cdc37d5e997f..4518516403444 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -193,7 +193,7 @@ function test_missing_asset_file_register_block_script_handle() { $metadata = array( 'file' => __FILE__, 'name' => 'unit-tests/test-block', - 'script' => 'file:./fixtures/missing-asset.js', + 'script' => 'file:./blocks/notice/missing-asset.js', ); $result = register_block_script_handle( $metadata, 'script' ); @@ -217,9 +217,9 @@ function test_handle_passed_register_block_script_handle() { */ function test_success_register_block_script_handle() { $metadata = array( - 'file' => __FILE__, + 'file' => DIR_TESTDATA . '/blocks/notice/block.json', 'name' => 'unit-tests/test-block', - 'script' => 'file:./fixtures/block.js', + 'script' => 'file:./block.js', ); $result = register_block_script_handle( $metadata, 'script' ); @@ -262,9 +262,9 @@ function test_handle_passed_register_block_style_handle() { */ function test_success_register_block_style_handle() { $metadata = array( - 'file' => __FILE__, + 'file' => DIR_TESTDATA . '/blocks/notice/block.json', 'name' => 'unit-tests/test-block', - 'style' => 'file:./fixtures/block.css', + 'style' => 'file:./block.css', ); $result = register_block_style_handle( $metadata, 'style' ); @@ -303,7 +303,7 @@ function test_metadata_not_found_in_the_current_directory() { */ function test_block_registers_with_metadata_fixture() { $result = register_block_type_from_metadata( - __DIR__ . '/fixtures' + DIR_TESTDATA . '/blocks/notice' ); $this->assertInstanceOf( 'WP_Block_Type', $result ); @@ -367,6 +367,44 @@ function test_block_registers_with_metadata_fixture() { $this->assertSame( 'my-plugin-notice-style', $result->style ); } + /** + * @ticket 000 + */ + function test_block_registers_with_metadata_i18n_support() { + function filter_set_locale_to_german() { + return 'de_DE'; + } + add_filter( 'locale', 'filter_set_locale_to_german' ); + load_textdomain( 'internationalized', WP_LANG_DIR . '/plugins/internationalized-plugin-de_DE.mo' ); + + $result = register_block_type_from_metadata( + DIR_TESTDATA . '/blocks/internationalized' + ); + + unload_textdomain( 'internationalized' ); + remove_filter( 'locale', 'filter_set_locale_to_german' ); + + $this->assertInstanceOf( 'WP_Block_Type', $result ); + $this->assertSame( 'tests/internationalized', $result->name ); + $this->assertSame( 'Das ist ein Dummy Plugin', $result->title ); + $this->assertSame( 'Das ist ein Dummy Plugin', $result->description ); + $this->assertSameSets( array( 'alert', 'Das ist ein Dummy Plugin' ), $result->keywords ); + $this->assertSame( + array( + array( + 'name' => 'default', + 'label' => 'Default', + 'isDefault' => true, + ), + array( + 'name' => 'other', + 'label' => 'Das ist ein Dummy Plugin', + ), + ), + $result->styles + ); + } + /** * @ticket 45109 */ @@ -433,7 +471,7 @@ public function test_filter_block_registration_metadata() { add_filter( 'block_type_metadata', $filter_metadata_registration, 10, 2 ); $result = register_block_type_from_metadata( - __DIR__ . '/fixtures' + DIR_TESTDATA . '/blocks/notice' ); remove_filter( 'block_type_metadata', $filter_metadata_registration ); @@ -451,7 +489,7 @@ public function test_filter_block_registration_metadata_settings() { add_filter( 'block_type_metadata_settings', $filter_metadata_registration, 10, 2 ); $result = register_block_type_from_metadata( - __DIR__ . '/fixtures' + DIR_TESTDATA . '/blocks/notice' ); remove_filter( 'block_type_metadata_settings', $filter_metadata_registration ); From 384f18b8710e4b24c1b3b9b4137f0476e912b6be Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Thu, 14 Jan 2021 18:09:03 +0100 Subject: [PATCH 3/5] Improve tests for i18n support --- package-lock.json | 2 +- src/wp-includes/blocks.php | 15 ++++++- .../data/blocks/internationalized/block.json | 21 --------- tests/phpunit/data/blocks/notice/block.json | 14 +++--- .../data/languages/plugins/notice-pl_PL.mo | Bin 0 -> 892 bytes .../data/languages/plugins/notice-pl_PL.po | 37 ++++++++++++++++ tests/phpunit/tests/blocks/register.php | 40 +++++++++--------- 7 files changed, 79 insertions(+), 50 deletions(-) delete mode 100644 tests/phpunit/data/blocks/internationalized/block.json create mode 100644 tests/phpunit/data/languages/plugins/notice-pl_PL.mo create mode 100644 tests/phpunit/data/languages/plugins/notice-pl_PL.po diff --git a/package-lock.json b/package-lock.json index 0c6a1c3e27e98..b8c08e97ed2d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6032,7 +6032,7 @@ }, "browserify-aes": { "version": "1.2.0", - "resolved": "http://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", + "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", "dev": true, "requires": { diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 3b2a57ea04b26..e9bb2b6674f9f 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -134,7 +134,15 @@ function register_block_script_handle( $metadata, $field_name ) { $script_asset['dependencies'], $script_asset['version'] ); - return $result ? $script_handle : false; + if ( ! $result ) { + return false; + } + + if ( ! empty( $metadata['textdomain'] ) ) { + wp_set_script_translations( $script_handle, $metadata['textdomain'] ); + } + + return $script_handle; } /** @@ -232,6 +240,11 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { foreach ( $property_mappings as $key => $mapped_key ) { if ( isset( $metadata[ $key ] ) ) { $value = $metadata[ $key ]; + if ( empty( $metadata['textdomain'] ) ) { + $settings[ $mapped_key ] = $value; + continue; + } + $textdomain = $metadata['textdomain']; switch ( $key ) { case 'title': case 'description': diff --git a/tests/phpunit/data/blocks/internationalized/block.json b/tests/phpunit/data/blocks/internationalized/block.json deleted file mode 100644 index b039899c33138..0000000000000 --- a/tests/phpunit/data/blocks/internationalized/block.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "tests/internationalized", - "title": "This is a dummy plugin", - "description": "This is a dummy plugin", - "keywords": [ - "alert", - "This is a dummy plugin" - ], - "styles": [ - { - "name": "default", - "label": "Default", - "isDefault": true - }, - { - "name": "other", - "label": "This is a dummy plugin" - } - ], - "textdomain": "internationalized" -} diff --git a/tests/phpunit/data/blocks/notice/block.json b/tests/phpunit/data/blocks/notice/block.json index ed60fd844021f..9a0ecc018da64 100644 --- a/tests/phpunit/data/blocks/notice/block.json +++ b/tests/phpunit/data/blocks/notice/block.json @@ -1,13 +1,13 @@ { "apiVersion": 2, - "name": "my-plugin/notice", + "name": "tests/notice", "title": "Notice", "category": "common", "parent": [ "core/group" ], "providesContext": { - "my-plugin/message": "message" + "tests/message": "message" }, "usesContext": [ "groupId" @@ -18,7 +18,7 @@ "alert", "message" ], - "textdomain": "my-plugin", + "textdomain": "notice", "attributes": { "message": { "type": "string", @@ -46,8 +46,8 @@ "message": "This is a notice!" } }, - "editorScript": "my-plugin-notice-editor-script", - "script": "my-plugin-notice-script", - "editorStyle": "my-plugin-notice-editor-style", - "style": "my-plugin-notice-style" + "editorScript": "tests-notice-editor-script", + "script": "tests-notice-script", + "editorStyle": "tests-notice-editor-style", + "style": "tests-notice-style" } diff --git a/tests/phpunit/data/languages/plugins/notice-pl_PL.mo b/tests/phpunit/data/languages/plugins/notice-pl_PL.mo new file mode 100644 index 0000000000000000000000000000000000000000..86652f97947c5ba9aa8b8d54f915ed4773c19982 GIT binary patch literal 892 zcmYjPO=}ZD7#_7&j0)meWWGTppQRyQ-t%)~UFL=Z1t zJ@xKyQ1Bu&;K`rh!GGaJeI{v=zU;&Ee!sKt%&$u;pBUr}a2eieFav5 z@4#u`2XGVkd1U_q`@Da^-xJV*v(Q&hF?Iob5xfGv0=@^n20jnYzQy-zqYcMrhgn9}ay3o1zu$gl zvLNHw0AAT6mKgn#GAFjW;u#s6YZdWIvLl|*>)cynT{?<*J*bBw2u0Z7;oYdwxD|v! zP-#ik8=_0Z%OXu$mF=zVjb)p#7E~T+-oX zj8t}yjMz|_?&4n}zP6jY$_w$36dCEXiFl%^n>${wHEMN4W~R6=EtS&sBVMZ{#n8w? zY-%&G5m)8Zw9R^qgZfDGy5d)xJiHMv>mSj0q)peha_b_Vrg2Jfx*vtrdIoi_DDQ|< zHMOe^gjA}uF6ZurQN5GJWV2K{XVA>6eK#nM)Tx)2-kCb}9!**l%xs*qgY9+o0NWGo zVOeT}V~)w<7AzL*7gx;ov$z+O$N}ziv7HyS)xa|MEjgn zPHaoT^&Fv5POgw#TW8+Tis_registered( $block_name ) ) { $registry->unregister( $block_name ); } @@ -308,7 +308,7 @@ function test_block_registers_with_metadata_fixture() { $this->assertInstanceOf( 'WP_Block_Type', $result ); $this->assertSame( 2, $result->api_version ); - $this->assertSame( 'my-plugin/notice', $result->name ); + $this->assertSame( 'tests/notice', $result->name ); $this->assertSame( 'Notice', $result->title ); $this->assertSame( 'common', $result->category ); $this->assertSameSets( array( 'core/group' ), $result->parent ); @@ -327,7 +327,7 @@ function test_block_registers_with_metadata_fixture() { ); $this->assertSame( array( - 'my-plugin/message' => 'message', + 'tests/message' => 'message', ), $result->provides_context ); @@ -361,44 +361,44 @@ function test_block_registers_with_metadata_fixture() { ), $result->example ); - $this->assertSame( 'my-plugin-notice-editor-script', $result->editor_script ); - $this->assertSame( 'my-plugin-notice-script', $result->script ); - $this->assertSame( 'my-plugin-notice-editor-style', $result->editor_style ); - $this->assertSame( 'my-plugin-notice-style', $result->style ); + $this->assertSame( 'tests-notice-editor-script', $result->editor_script ); + $this->assertSame( 'tests-notice-script', $result->script ); + $this->assertSame( 'tests-notice-editor-style', $result->editor_style ); + $this->assertSame( 'tests-notice-style', $result->style ); } /** * @ticket 000 */ function test_block_registers_with_metadata_i18n_support() { - function filter_set_locale_to_german() { - return 'de_DE'; + function filter_set_locale_to_polish() { + return 'pl_PL'; } - add_filter( 'locale', 'filter_set_locale_to_german' ); - load_textdomain( 'internationalized', WP_LANG_DIR . '/plugins/internationalized-plugin-de_DE.mo' ); + add_filter( 'locale', 'filter_set_locale_to_polish' ); + load_textdomain( 'notice', WP_LANG_DIR . '/plugins/notice-pl_PL.mo' ); $result = register_block_type_from_metadata( - DIR_TESTDATA . '/blocks/internationalized' + DIR_TESTDATA . '/blocks/notice' ); - unload_textdomain( 'internationalized' ); - remove_filter( 'locale', 'filter_set_locale_to_german' ); + unload_textdomain( 'notice' ); + remove_filter( 'locale', 'filter_set_locale_to_polish' ); $this->assertInstanceOf( 'WP_Block_Type', $result ); - $this->assertSame( 'tests/internationalized', $result->name ); - $this->assertSame( 'Das ist ein Dummy Plugin', $result->title ); - $this->assertSame( 'Das ist ein Dummy Plugin', $result->description ); - $this->assertSameSets( array( 'alert', 'Das ist ein Dummy Plugin' ), $result->keywords ); + $this->assertSame( 'tests/notice', $result->name ); + $this->assertSame( 'Powiadomienie', $result->title ); + $this->assertSame( 'Wyświetla ostrzeżenie, błąd lub powiadomienie o sukcesie…', $result->description ); + $this->assertSameSets( array( 'ostrzeżenie', 'wiadomość' ), $result->keywords ); $this->assertSame( array( array( 'name' => 'default', - 'label' => 'Default', + 'label' => 'Domyślny', 'isDefault' => true, ), array( 'name' => 'other', - 'label' => 'Das ist ein Dummy Plugin', + 'label' => 'Inny', ), ), $result->styles From d10553403eb0e1bc5fc9e44d413251a9902e8e62 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Thu, 14 Jan 2021 18:28:43 +0100 Subject: [PATCH 4/5] Use translate_with_gettext_context rather than translate --- src/wp-includes/blocks.php | 8 ++++---- .../data/languages/plugins/notice-pl_PL.mo | Bin 892 -> 986 bytes .../data/languages/plugins/notice-pl_PL.po | 8 +++++++- tests/phpunit/tests/blocks/register.php | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index e9bb2b6674f9f..067ef546ae470 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -248,8 +248,8 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { switch ( $key ) { case 'title': case 'description': - // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain - $settings[ $mapped_key ] = translate( $value, $textdomain ); + // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralContext,WordPress.WP.I18n.NonSingularStringLiteralDomain + $settings[ $mapped_key ] = translate_with_gettext_context( $value, sprintf( 'block %s', $key ), $textdomain ); break; case 'keywords': $settings[ $mapped_key ] = array(); @@ -259,7 +259,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { foreach ( $value as $keyword ) { // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain - $settings[ $mapped_key ][] = translate( $keyword, $textdomain ); + $settings[ $mapped_key ][] = translate_with_gettext_context( $keyword, 'block keyword', $textdomain ); } break; @@ -272,7 +272,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { foreach ( $value as $style ) { if ( ! empty( $style['label'] ) ) { // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain - $style['label'] = translate( $style['label'], $textdomain ); + $style['label'] = translate_with_gettext_context( $style['label'], 'block style label', $textdomain ); } $settings[ $mapped_key ][] = $style; } diff --git a/tests/phpunit/data/languages/plugins/notice-pl_PL.mo b/tests/phpunit/data/languages/plugins/notice-pl_PL.mo index 86652f97947c5ba9aa8b8d54f915ed4773c19982..284872cf6f88ad9f36ae6ac347cd0372d56b5d04 100644 GIT binary patch delta 354 zcmYkzze)o^5C-r$vnKejQ9`f~4q_ol8Vivi+N4R71Pj4(b35vqy<6E`30LJ6A}Q1Q z0%B!hDO!jR;DcC+_ysTGz_-8Incc7QM`gS{IwYb;WCQs`s>pIgvy(g&T_|48XDNFxFSwZckQq#xDi-YFg{=-r98cph@v#pj*^XI9_a%yKddUmL#vZ>}wGyMR+ Cty0DS delta 241 zcmcb`{)cUXN~LL z3#0{rGz*ZH1Jd?DS{X?50O@2P%?+drfHY7G0}~L#0LUJo9&ND2FhP(dK(!1EE~#mW zr8y-Ge)%Pt$*BzfB^jwj3=>al^Cae^7L_pMrWO|`rcX|0G-WZjGBMdahw%iXj7xrQ h< Date: Tue, 19 Jan 2021 11:36:35 +0100 Subject: [PATCH 5/5] Add translations only when textdomain set --- src/wp-includes/blocks.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 067ef546ae470..ace9811f32e1b 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -235,8 +235,6 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { 'apiVersion' => 'api_version', ); - $textdomain = isset( $metadata['textdomain'] ) ? $metadata['textdomain'] : 'default'; - foreach ( $property_mappings as $key => $mapped_key ) { if ( isset( $metadata[ $key ] ) ) { $value = $metadata[ $key ];