From 987b7e66c8812482a686805ef2de50ba3a23bfb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Tue, 9 Feb 2021 18:51:02 +0100 Subject: [PATCH 1/3] Add customTemplates field --- lib/experimental-i18n-theme.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/experimental-i18n-theme.json b/lib/experimental-i18n-theme.json index 80c7011208d53..fce88da63d43b 100644 --- a/lib/experimental-i18n-theme.json +++ b/lib/experimental-i18n-theme.json @@ -14,5 +14,8 @@ "gradients": [ { "name": "Gradient name" } ] } } + }, + "customTemplates": { + "*": { "title": "Title of the CPT" } } } From 9370ff6489d311ac2060db11f9c68350158e8232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Thu, 11 Feb 2021 19:34:57 +0100 Subject: [PATCH 2/3] Adapt data stored in i18n file to format --- lib/experimental-i18n-theme.json | 2 +- phpunit/class-wp-theme-json-resolver-test.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/experimental-i18n-theme.json b/lib/experimental-i18n-theme.json index fce88da63d43b..30c3ef0ede6d5 100644 --- a/lib/experimental-i18n-theme.json +++ b/lib/experimental-i18n-theme.json @@ -16,6 +16,6 @@ } }, "customTemplates": { - "*": { "title": "Title of the CPT" } + "*": [ { "title": "Title of the custom template" } ] } } diff --git a/phpunit/class-wp-theme-json-resolver-test.php b/phpunit/class-wp-theme-json-resolver-test.php index 6c2fa216bc9b0..fee915d6488ce 100644 --- a/phpunit/class-wp-theme-json-resolver-test.php +++ b/phpunit/class-wp-theme-json-resolver-test.php @@ -52,6 +52,11 @@ function test_presets_are_extracted() { 'key' => 'name', 'context' => 'Gradient name', ), + array( + 'path' => array( 'customTemplates', '*' ), + 'key' => 'title', + 'context' => 'Title of the custom template', + ), ); $this->assertEquals( $expected, $actual ); From 09a447a7900cccdd7e2902d90d22e4365297f3da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Fri, 12 Feb 2021 12:32:43 +0100 Subject: [PATCH 3/3] Express unknow keys as * whether they are unknow keys or numeric. --- lib/class-wp-theme-json-resolver.php | 23 +++++++++++-------- lib/experimental-i18n-theme.json | 21 +++++++++-------- phpunit/class-wp-theme-json-resolver-test.php | 16 ++++++------- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/lib/class-wp-theme-json-resolver.php b/lib/class-wp-theme-json-resolver.php index e67492896223c..db7eb6c04862d 100644 --- a/lib/class-wp-theme-json-resolver.php +++ b/lib/class-wp-theme-json-resolver.php @@ -118,16 +118,19 @@ private static function get_from_file( $file_path ) { private static function extract_paths_to_translate( $i18n_partial, $current_path = array() ) { $result = array(); foreach ( $i18n_partial as $property => $partial_child ) { - if ( is_numeric( $property ) ) { - foreach ( $partial_child as $key => $context ) { - return array( - array( - 'path' => $current_path, - 'key' => $key, - 'context' => $context, - ), - ); - } + if ( + is_array( $partial_child ) && + array_key_exists( 'key', $partial_child ) && + array_key_exists( 'context', $partial_child ) + ) { + $last_key = is_numeric( $property ) ? '*' : $property; + return array( + array( + 'path' => array_merge( $current_path, [ $last_key ] ), + 'key' => $partial_child['key'], + 'context' => $partial_child['context'], + ), + ); } $result = array_merge( $result, diff --git a/lib/experimental-i18n-theme.json b/lib/experimental-i18n-theme.json index 30c3ef0ede6d5..734cf9a3a046a 100644 --- a/lib/experimental-i18n-theme.json +++ b/lib/experimental-i18n-theme.json @@ -2,20 +2,23 @@ "settings": { "*": { "typography": { - "fontSizes": [ { "name": "Font size name" } ], - "fontStyles": [ { "name": "Font style name" } ], - "fontWeights": [ { "name": "Font weight name" } ], - "fontFamilies": [ { "name": "Font family name" } ], - "textTransforms": [ { "name": "Text transform name" } ], - "textDecorations": [ { "name": "Text decoration name" } ] + "fontSizes": [ { "key": "name", "context": "Font size name" } ], + "fontStyles": [ { "key": "name", "context": "Font style name" } ], + "fontWeights": [ { "key": "name", "context": "Font weight name" } ], + "fontFamilies": [ { "key": "name", "context": "Font family name" } ], + "textTransforms": [ { "key": "name", "context": "Text transform name" } ], + "textDecorations": [ { "key": "name", "context": "Text decoration name" } ] }, "color": { - "palette": [ { "name": "Color name" } ], - "gradients": [ { "name": "Gradient name" } ] + "palette": [ { "key": "name", "context": "Color name" } ], + "gradients": [ { "key": "name", "context": "Gradient name" } ] } } }, "customTemplates": { - "*": [ { "title": "Title of the custom template" } ] + "*": { + "key": "title", + "context": "Title of the custom template" + } } } diff --git a/phpunit/class-wp-theme-json-resolver-test.php b/phpunit/class-wp-theme-json-resolver-test.php index fee915d6488ce..0ae3210a30b50 100644 --- a/phpunit/class-wp-theme-json-resolver-test.php +++ b/phpunit/class-wp-theme-json-resolver-test.php @@ -13,42 +13,42 @@ function test_presets_are_extracted() { $expected = array( array( - 'path' => array( 'settings', '*', 'typography', 'fontSizes' ), + 'path' => array( 'settings', '*', 'typography', 'fontSizes', '*' ), 'key' => 'name', 'context' => 'Font size name', ), array( - 'path' => array( 'settings', '*', 'typography', 'fontStyles' ), + 'path' => array( 'settings', '*', 'typography', 'fontStyles', '*' ), 'key' => 'name', 'context' => 'Font style name', ), array( - 'path' => array( 'settings', '*', 'typography', 'fontWeights' ), + 'path' => array( 'settings', '*', 'typography', 'fontWeights', '*' ), 'key' => 'name', 'context' => 'Font weight name', ), array( - 'path' => array( 'settings', '*', 'typography', 'fontFamilies' ), + 'path' => array( 'settings', '*', 'typography', 'fontFamilies', '*' ), 'key' => 'name', 'context' => 'Font family name', ), array( - 'path' => array( 'settings', '*', 'typography', 'textTransforms' ), + 'path' => array( 'settings', '*', 'typography', 'textTransforms', '*' ), 'key' => 'name', 'context' => 'Text transform name', ), array( - 'path' => array( 'settings', '*', 'typography', 'textDecorations' ), + 'path' => array( 'settings', '*', 'typography', 'textDecorations', '*' ), 'key' => 'name', 'context' => 'Text decoration name', ), array( - 'path' => array( 'settings', '*', 'color', 'palette' ), + 'path' => array( 'settings', '*', 'color', 'palette', '*' ), 'key' => 'name', 'context' => 'Color name', ), array( - 'path' => array( 'settings', '*', 'color', 'gradients' ), + 'path' => array( 'settings', '*', 'color', 'gradients', '*' ), 'key' => 'name', 'context' => 'Gradient name', ),