<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[51599] trunk: Blocks: Add support for `variations in `block.json` file</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/51599">51599</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/51599","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>gziolo</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-08-11 09:06:31 +0000 (Wed, 11 Aug 2021)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Blocks: Add support for `variations in `block.json` file

We integrated variations with block types and the corresponding REST API endpoint in <a href="https://core.trac.wordpress.org/ticket/52688">#52688</a>. It's a follow-up patch to add missing support to the `block.json` metadata file when using `register_block_type`.

Some fields for variations are translatable.Therefore, i18n schema was copied over from Gutenberg: https://github.com/WordPress/gutenberg/blob/trunk/packages/blocks/src/api/i18n-block.json. The accompanying implementation was adapted as `translate_settings_using_i18n_schema`.

Props: gwwar, swissspidy, schlessera, jorgefilipecosta.
Fixes <a href="https://core.trac.wordpress.org/ticket/53238">#53238</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksphp">trunk/src/wp-includes/blocks.php</a></li>
<li><a href="#trunksrcwpincludesclasswpthemejsonresolverphp">trunk/src/wp-includes/class-wp-theme-json-resolver.php</a></li>
<li><a href="#trunksrcwpincludesfunctionsphp">trunk/src/wp-includes/functions.php</a></li>
<li><a href="#trunksrcwpincludesl10nphp">trunk/src/wp-includes/l10n.php</a></li>
<li><a href="#trunktestsphpunitdatablocksnoticeblockjson">trunk/tests/phpunit/data/blocks/notice/block.json</a></li>
<li><a href="#trunktestsphpunitdatalanguagespluginsnoticepl_PLpo">trunk/tests/phpunit/data/languages/plugins/notice-pl_PL.po</a></li>
<li><a href="#trunktestsphpunittestsblocksregisterphp">trunk/tests/phpunit/tests/blocks/register.php</a></li>
<li><a href="#trunktestsphpunittestsfunctionsphp">trunk/tests/phpunit/tests/functions.php</a></li>
<li><a href="#trunktestsphpunitteststhemewpThemeJsonResolverphp">trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocki18njson">trunk/src/wp-includes/block-i18n.json</a></li>
<li><a href="#trunktestsphpunittestsl10ntranslateSettingsUsingI18nSchemaphp">trunk/tests/phpunit/tests/l10n/translateSettingsUsingI18nSchema.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocki18njson"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/wp-includes/block-i18n.json</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-i18n.json                             (rev 0)
+++ trunk/src/wp-includes/block-i18n.json       2021-08-11 09:06:31 UTC (rev 51599)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,17 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+{
+       "title": "block title",
+       "description": "block description",
+       "keywords": [ "block keyword" ],
+       "styles": [
+               {
+                       "label": "block style label"
+               }
+       ],
+       "variations": [
+               {
+                       "title": "block variation title",
+                       "description": "block variation description",
+                       "keywords": [ "block variation keyword" ]
+               }
+       ]
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/src/wp-includes/block-i18n.json
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunksrcwpincludesblocksphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/blocks.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/blocks.php  2021-08-10 21:13:38 UTC (rev 51598)
+++ trunk/src/wp-includes/blocks.php    2021-08-11 09:06:31 UTC (rev 51599)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -188,10 +188,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Gets i18n schema for block's metadata read from `block.json` file.
+ *
+ * @since 5.9.0
+ *
+ * @return array The schema for block's metadata.
+ */
+function get_block_metadata_i18n_schema() {
+       static $i18n_block_schema;
+
+       if ( ! isset( $i18n_block_schema ) ) {
+               $i18n_block_schema = wp_json_file_decode( __DIR__ . '/block-i18n.json' );
+       }
+
+       return $i18n_block_schema;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Registers a block type from the metadata stored in the `block.json` file.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 5.5.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.9.0 Added support for the `viewScript` field.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 5.7.0 Added support for `textdomain` field and i18n handling for all translatable fields.
+ * @since 5.9.0 Added support for `variations` and `viewScript` fields.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param string $file_or_folder Path to the JSON file with metadata definition for
</span><span class="cx" style="display: block; padding: 0 10px">  *                               the block or path to the folder where the `block.json` file is located.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -209,7 +227,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return false;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $metadata = json_decode( file_get_contents( $metadata_file ), true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $metadata = wp_json_file_decode( $metadata_file, array( 'associative' => true ) );
</ins><span class="cx" style="display: block; padding: 0 10px">         if ( ! is_array( $metadata ) || empty( $metadata['name'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                return false;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -238,6 +256,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        $settings          = array();
</span><span class="cx" style="display: block; padding: 0 10px">        $property_mappings = array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                'apiVersion'      => 'api_version',
</ins><span class="cx" style="display: block; padding: 0 10px">                 'title'           => 'title',
</span><span class="cx" style="display: block; padding: 0 10px">                'category'        => 'category',
</span><span class="cx" style="display: block; padding: 0 10px">                'parent'          => 'parent',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -249,54 +268,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                'usesContext'     => 'uses_context',
</span><span class="cx" style="display: block; padding: 0 10px">                'supports'        => 'supports',
</span><span class="cx" style="display: block; padding: 0 10px">                'styles'          => 'styles',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                'variations'      => 'variations',
</ins><span class="cx" style="display: block; padding: 0 10px">                 'example'         => 'example',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                'apiVersion'      => 'api_version',
</del><span class="cx" style="display: block; padding: 0 10px">         );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        $textdomain        = ! empty( $metadata['textdomain'] ) ? $metadata['textdomain'] : null;
+       $i18n_schema       = get_block_metadata_i18n_schema();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        foreach ( $property_mappings as $key => $mapped_key ) {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( isset( $metadata[ $key ] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $value = $metadata[ $key ];
-                       if ( empty( $metadata['textdomain'] ) ) {
-                               $settings[ $mapped_key ] = $value;
-                               continue;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $settings[ $mapped_key ] = $metadata[ $key ];
+                       if ( $textdomain && isset( $i18n_schema->$key ) ) {
+                               $settings[ $mapped_key ] = translate_settings_using_i18n_schema( $i18n_schema->$key, $settings[ $key ], $textdomain );
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $textdomain = $metadata['textdomain'];
-                       switch ( $key ) {
-                               case 'title':
-                               case 'description':
-                                       // 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();
-                                       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_with_gettext_context( $keyword, 'block 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_with_gettext_context( $style['label'], 'block style label', $textdomain );
-                                               }
-                                               $settings[ $mapped_key ][] = $style;
-                                       }
-
-                                       break;
-                               default:
-                                       $settings[ $mapped_key ] = $value;
-                       }
</del><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpthemejsonresolverphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-theme-json-resolver.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-theme-json-resolver.php    2021-08-10 21:13:38 UTC (rev 51598)
+++ trunk/src/wp-includes/class-wp-theme-json-resolver.php      2021-08-11 09:06:31 UTC (rev 51599)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -40,12 +40,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">        private static $theme_has_support = null;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Structure to hold i18n metadata.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Container to keep loaded i18n schema for `theme.json`.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @since 5.8.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @since 5.9.0
</ins><span class="cx" style="display: block; padding: 0 10px">          * @var array
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        private static $theme_json_i18n = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private static $i18n_schema = null;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * Processes a file that adheres to the theme.json schema
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -59,17 +59,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        private static function read_json_file( $file_path ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $config = array();
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $file_path ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $decoded_file = json_decode(
-                               file_get_contents( $file_path ),
-                               true
-                       );
-
-                       $json_decoding_error = json_last_error();
-                       if ( JSON_ERROR_NONE !== $json_decoding_error ) {
-                               trigger_error( "Error when decoding a theme.json schema at path $file_path " . json_last_error_msg() );
-                               return $config;
-                       }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $decoded_file = wp_json_file_decode( $file_path, array( 'associative' => true ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( is_array( $decoded_file ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $config = $decoded_file;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -78,105 +68,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Converts a tree as in i18n-theme.json into a linear array
-        * containing metadata to translate a theme.json file.
-        *
-        * For example, given this input:
-        *
-        *     {
-        *       "settings": {
-        *         "*": {
-        *           "typography": {
-        *             "fontSizes": [ { "name": "Font size name" } ],
-        *             "fontStyles": [ { "name": "Font size name" } ]
-        *           }
-        *         }
-        *       }
-        *     }
-        *
-        * will return this output:
-        *
-        *     [
-        *       0 => [
-        *         'path'    => [ 'settings', '*', 'typography', 'fontSizes' ],
-        *         'key'     => 'name',
-        *         'context' => 'Font size name'
-        *       ],
-        *       1 => [
-        *         'path'    => [ 'settings', '*', 'typography', 'fontStyles' ],
-        *         'key'     => 'name',
-        *         'context' => 'Font style name'
-        *       ]
-        *     ]
-        *
-        * @since 5.8.0
-        *
-        * @param array $i18n_partial A tree that follows the format of i18n-theme.json.
-        * @param array $current_path Optional. Keeps track of the path as we walk down the given tree.
-        *                            Default empty array.
-        * @return array A linear array containing the paths to translate.
-        */
-       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 ) {
-                                       $result[] = array(
-                                               'path'    => $current_path,
-                                               'key'     => $key,
-                                               'context' => $context,
-                                       );
-                               }
-                               return $result;
-                       }
-                       $result = array_merge(
-                               $result,
-                               self::extract_paths_to_translate( $partial_child, array_merge( $current_path, array( $property ) ) )
-                       );
-               }
-               return $result;
-       }
-
-       /**
</del><span class="cx" style="display: block; padding: 0 10px">          * Returns a data structure used in theme.json translation.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 5.8.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @deprecated 5.9.0
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array An array of theme.json fields that are translatable and the keys that are translatable.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public static function get_fields_to_translate() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( null === self::$theme_json_i18n ) {
-                       $file_structure        = self::read_json_file( __DIR__ . '/theme-i18n.json' );
-                       self::$theme_json_i18n = self::extract_paths_to_translate( $file_structure );
-               }
-               return self::$theme_json_i18n;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         _deprecated_function( __METHOD__, '5.9.0' );
+               return array();
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Translates a chunk of the loaded theme.json structure.
-        *
-        * @since 5.8.0
-        *
-        * @param array  $array_to_translate The chunk of theme.json to translate.
-        * @param string $key                The key of the field that contains the string to translate.
-        * @param string $context            The context to apply in the translation call.
-        * @param string $domain             Text domain. Unique identifier for retrieving translated strings.
-        * @return array Returns the modified $theme_json chunk.
-        */
-       private static function translate_theme_json_chunk( array $array_to_translate, $key, $context, $domain ) {
-               foreach ( $array_to_translate as $item_key => $item_to_translate ) {
-                       if ( empty( $item_to_translate[ $key ] ) ) {
-                               continue;
-                       }
-
-                       // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralContext,WordPress.WP.I18n.NonSingularStringLiteralDomain
-                       $array_to_translate[ $item_key ][ $key ] = translate_with_gettext_context( $array_to_translate[ $item_key ][ $key ], $context, $domain );
-               }
-
-               return $array_to_translate;
-       }
-
-       /**
</del><span class="cx" style="display: block; padding: 0 10px">          * Given a theme.json structure modifies it in place to update certain values
</span><span class="cx" style="display: block; padding: 0 10px">         * by its translated strings according to the language set by the user.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -188,50 +92,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array Returns the modified $theme_json_structure.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        private static function translate( $theme_json, $domain = 'default' ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $fields = self::get_fields_to_translate();
-               foreach ( $fields as $field ) {
-                       $path    = $field['path'];
-                       $key     = $field['key'];
-                       $context = $field['context'];
-
-                       /*
-                        * We need to process the paths that include '*' separately.
-                        * One example of such a path would be:
-                        * [ 'settings', 'blocks', '*', 'color', 'palette' ]
-                        */
-                       $nodes_to_iterate = array_keys( $path, '*', true );
-                       if ( ! empty( $nodes_to_iterate ) ) {
-                               /*
-                                * At the moment, we only need to support one '*' in the path, so take it directly.
-                                * - base will be [ 'settings', 'blocks' ]
-                                * - data will be [ 'color', 'palette' ]
-                                */
-                               $base_path = array_slice( $path, 0, $nodes_to_iterate[0] );
-                               $data_path = array_slice( $path, $nodes_to_iterate[0] + 1 );
-                               $base_tree = _wp_array_get( $theme_json, $base_path, array() );
-                               foreach ( $base_tree as $node_name => $node_data ) {
-                                       $array_to_translate = _wp_array_get( $node_data, $data_path, null );
-                                       if ( is_null( $array_to_translate ) ) {
-                                               continue;
-                                       }
-
-                                       // Whole path will be [ 'settings', 'blocks', 'core/paragraph', 'color', 'palette' ].
-                                       $whole_path       = array_merge( $base_path, array( $node_name ), $data_path );
-                                       $translated_array = self::translate_theme_json_chunk( $array_to_translate, $key, $context, $domain );
-                                       _wp_array_set( $theme_json, $whole_path, $translated_array );
-                               }
-                       } else {
-                               $array_to_translate = _wp_array_get( $theme_json, $path, null );
-                               if ( is_null( $array_to_translate ) ) {
-                                       continue;
-                               }
-
-                               $translated_array = self::translate_theme_json_chunk( $array_to_translate, $key, $context, $domain );
-                               _wp_array_set( $theme_json, $path, $translated_array );
-                       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( null === self::$i18n_schema ) {
+                       $i18n_schema = wp_json_file_decode( __DIR__ . '/theme-i18n.json' );
+                       self::$i18n_schema = null === $i18n_schema ? array() : $i18n_schema;
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                return $theme_json;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         return translate_settings_using_i18n_schema( self::$i18n_schema, $theme_json, $domain );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -365,7 +231,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                self::$core              = null;
</span><span class="cx" style="display: block; padding: 0 10px">                self::$theme             = null;
</span><span class="cx" style="display: block; padding: 0 10px">                self::$theme_has_support = null;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                self::$theme_json_i18n   = null;
</del><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/functions.php       2021-08-10 21:13:38 UTC (rev 51598)
+++ trunk/src/wp-includes/functions.php 2021-08-11 09:06:31 UTC (rev 51599)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4268,6 +4268,54 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Reads and decodes a JSON file.
+ *
+ * @since 5.9.0
+ *
+ * @param string $filename Path to the JSON file.
+ * @param array  $options  {
+ *     Optional. Options to be used with `json_decode()`.
+ *
+ *     @type bool associative Optional. When `true`, JSON objects will be returned as associative arrays.
+ *                            When `false`, JSON objects will be returned as objects.
+ * }
+ *
+ * @return mixed Returns the value encoded in JSON in appropriate PHP type.
+ *               `null` is returned if the file is not found, or its content can't be decoded.
+ */
+function wp_json_file_decode( $filename, $options = array() ) {
+       $result   = null;
+       $filename = wp_normalize_path( realpath( $filename ) );
+       if ( ! file_exists( $filename ) ) {
+               trigger_error(
+                       sprintf(
+                               /* translators: %s: Path to the JSON file. */
+                               __( "File %s doesn't exist!" ),
+                               $filename
+                       )
+               );
+               return $result;
+       }
+
+       $options      = wp_parse_args( $options, array( 'associative' => false ) );
+       $decoded_file = json_decode( file_get_contents( $filename ), $options['associative'] );
+
+       if ( JSON_ERROR_NONE !== json_last_error() ) {
+               trigger_error(
+                       sprintf(
+                               /* translators: 1: Path to the JSON file, 2: Error message. */
+                               __( 'Error when decoding a JSON file at path %1$s: %2$s' ),
+                               $filename,
+                               json_last_error_msg()
+                       )
+               );
+               return $result;
+       }
+
+       return $decoded_file;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Retrieve the WordPress home page URL.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * If the constant named 'WP_HOME' exists, then it will be used and returned
</span></span></pre></div>
<a id="trunksrcwpincludesl10nphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/l10n.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/l10n.php    2021-08-10 21:13:38 UTC (rev 51598)
+++ trunk/src/wp-includes/l10n.php      2021-08-11 09:06:31 UTC (rev 51599)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1712,3 +1712,47 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        return $wp_locale_switcher->is_switched();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Translates the provided settings value using its i18n schema.
+ *
+ * @since 5.9.0
+ * @access private
+ *
+ * @param string|string[]|array[]|object $i18n_schema I18n schema for the setting.
+ * @param string|string[]|array[]        $settings    Value for the settings.
+ * @param string                         $textdomain  Textdomain to use with translations.
+ *
+ * @return string|string[]|array[] Translated settings.
+ */
+function translate_settings_using_i18n_schema( $i18n_schema, $settings, $textdomain ) {
+       if ( empty( $i18n_schema ) || empty( $settings ) || empty( $textdomain ) ) {
+               return $settings;
+       }
+
+       if ( is_string( $i18n_schema ) && is_string( $settings ) ) {
+               return translate_with_gettext_context( $settings, $i18n_schema, $textdomain );
+       }
+       if ( is_array( $i18n_schema ) && is_array( $settings ) ) {
+               $translated_settings = array();
+               foreach ( $settings as $value ) {
+                       $translated_settings[] = translate_settings_using_i18n_schema( $i18n_schema[0], $value, $textdomain );
+               }
+               return $translated_settings;
+       }
+       if ( is_object( $i18n_schema ) && is_array( $settings ) ) {
+               $group_key           = '*';
+               $translated_settings = array();
+               foreach ( $settings as $key => $value ) {
+                       if ( isset( $i18n_schema->$key ) ) {
+                               $translated_settings[ $key ] = translate_settings_using_i18n_schema( $i18n_schema->$key, $value, $textdomain );
+                       } elseif ( isset( $i18n_schema->$group_key ) ) {
+                               $translated_settings[ $key ] = translate_settings_using_i18n_schema( $i18n_schema->$group_key, $value, $textdomain );
+                       } else {
+                               $translated_settings[ $key ] = $value;
+                       }
+               }
+               return $translated_settings;
+       }
+       return $settings;
+}
</ins></span></pre></div>
<a id="trunktestsphpunitdatablocksnoticeblockjson"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/data/blocks/notice/block.json</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/blocks/notice/block.json 2021-08-10 21:13:38 UTC (rev 51598)
+++ trunk/tests/phpunit/data/blocks/notice/block.json   2021-08-11 09:06:31 UTC (rev 51599)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -41,6 +41,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        "label": "Other"
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">        ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        "variations": [
+               {
+                       "name": "error",
+                       "title": "Error",
+                       "description": "Shows error.",
+                       "keywords": [ "failure" ]
+               }
+       ],
</ins><span class="cx" style="display: block; padding: 0 10px">         "example": {
</span><span class="cx" style="display: block; padding: 0 10px">                "attributes": {
</span><span class="cx" style="display: block; padding: 0 10px">                        "message": "This is a notice!"
</span></span></pre></div>
<a id="trunktestsphpunitdatalanguagespluginsnoticepl_PLpo"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/data/languages/plugins/notice-pl_PL.po</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/languages/plugins/notice-pl_PL.po        2021-08-10 21:13:38 UTC (rev 51598)
+++ trunk/tests/phpunit/data/languages/plugins/notice-pl_PL.po  2021-08-11 09:06:31 UTC (rev 51599)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2,12 +2,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> msgstr ""
</span><span class="cx" style="display: block; padding: 0 10px"> "Project-Id-Version: \n"
</span><span class="cx" style="display: block; padding: 0 10px"> "POT-Creation-Date: 2015-12-31 16:31+0100\n"
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-"PO-Revision-Date: 2021-01-14 18:26+0100\n"
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+"PO-Revision-Date: 2021-07-15 13:36+0200\n"
</ins><span class="cx" style="display: block; padding: 0 10px"> "Language: pl_PL\n"
</span><span class="cx" style="display: block; padding: 0 10px"> "MIME-Version: 1.0\n"
</span><span class="cx" style="display: block; padding: 0 10px"> "Content-Type: text/plain; charset=UTF-8\n"
</span><span class="cx" style="display: block; padding: 0 10px"> "Content-Transfer-Encoding: 8bit\n"
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-"X-Generator: Poedit 2.4.2\n"
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+"X-Generator: Poedit 3.0\n"
</ins><span class="cx" style="display: block; padding: 0 10px"> "X-Poedit-Basepath: .\n"
</span><span class="cx" style="display: block; padding: 0 10px"> "Plural-Forms: nplurals=2; plural=(n != 1);\n"
</span><span class="cx" style="display: block; padding: 0 10px"> "X-Poedit-KeywordsList: __;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;"
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -41,3 +41,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> msgctxt "block style label"
</span><span class="cx" style="display: block; padding: 0 10px"> msgid "Other"
</span><span class="cx" style="display: block; padding: 0 10px"> msgstr "Inny"
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+msgctxt "block variation title"
+msgid "Error"
+msgstr "Błąd"
+
+msgctxt "block variation description"
+msgid "Shows error."
+msgstr "Wyświetla błąd."
+
+msgctxt "block variation keyword"
+msgid "failure"
+msgstr "niepowodzenie"
</ins></span></pre></div>
<a id="trunktestsphpunittestsblocksregisterphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/blocks/register.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/blocks/register.php     2021-08-10 21:13:38 UTC (rev 51598)
+++ trunk/tests/phpunit/tests/blocks/register.php       2021-08-11 09:06:31 UTC (rev 51599)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -70,6 +70,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Returns Polish locale string.
+        *
+        * @return string
+        */
+       function filter_set_locale_to_polish() {
+               return 'pl_PL';
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @ticket 45109
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        function test_register_affects_main_registry() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -372,6 +381,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame(
</span><span class="cx" style="display: block; padding: 0 10px">                        array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                array(
+                                       'name'        => 'error',
+                                       'title'       => 'Error',
+                                       'description' => 'Shows error.',
+                                       'keywords'    => array( 'failure' ),
+                               ),
+                       ),
+                       $result->variations
+               );
+               $this->assertSame(
+                       array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'attributes' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'message' => 'This is a notice!',
</span><span class="cx" style="display: block; padding: 0 10px">                                ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -407,10 +427,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 52301
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        function test_block_registers_with_metadata_i18n_support() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                function filter_set_locale_to_polish() {
-                       return 'pl_PL';
-               }
-               add_filter( 'locale', 'filter_set_locale_to_polish' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         add_filter( 'locale', array( $this, 'filter_set_locale_to_polish' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 load_textdomain( 'notice', WP_LANG_DIR . '/plugins/notice-pl_PL.mo' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $result = register_block_type_from_metadata(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -418,7 +435,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                unload_textdomain( 'notice' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                remove_filter( 'locale', 'filter_set_locale_to_polish' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         remove_filter( 'locale', array( $this, 'filter_set_locale_to_polish' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertInstanceOf( 'WP_Block_Type', $result );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 'tests/notice', $result->name );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -439,6 +456,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><span class="cx" style="display: block; padding: 0 10px">                        $result->styles
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertSame(
+                       array(
+                               array(
+                                       'name'        => 'error',
+                                       'title'       => 'Błąd',
+                                       'description' => 'Wyświetla błąd.',
+                                       'keywords'    => array( 'niepowodzenie' ),
+                               ),
+                       ),
+                       $result->variations
+               );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span></span></pre></div>
<a id="trunktestsphpunittestsfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/functions.php   2021-08-10 21:13:38 UTC (rev 51598)
+++ trunk/tests/phpunit/tests/functions.php     2021-08-11 09:06:31 UTC (rev 51599)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1038,6 +1038,31 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 53238
+        */
+       function test_wp_json_file_decode() {
+               $result = wp_json_file_decode(
+                       DIR_TESTDATA . '/blocks/notice/block.json'
+               );
+
+               $this->assertIsObject( $result );
+               $this->assertSame( 'tests/notice', $result->name );
+       }
+
+       /**
+        * @ticket 53238
+        */
+       function test_wp_json_file_decode_associative_array() {
+               $result = wp_json_file_decode(
+                       DIR_TESTDATA . '/blocks/notice/block.json',
+                       array( 'associative' => true )
+               );
+
+               $this->assertIsArray( $result );
+               $this->assertSame( 'tests/notice', $result['name'] );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @ticket 36054
</span><span class="cx" style="display: block; padding: 0 10px">         * @dataProvider datetime_provider
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span></span></pre></div>
<a id="trunktestsphpunittestsl10ntranslateSettingsUsingI18nSchemaphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/l10n/translateSettingsUsingI18nSchema.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/l10n/translateSettingsUsingI18nSchema.php                               (rev 0)
+++ trunk/tests/phpunit/tests/l10n/translateSettingsUsingI18nSchema.php 2021-08-11 09:06:31 UTC (rev 51599)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,99 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group l10n
+ * @group i18n
+ */
+class Tests_L10n_TranslateSettingsUsingI18nSchema extends WP_UnitTestCase {
+       /**
+        * Returns Polish locale string.
+        *
+        * @return string
+        */
+       function filter_set_locale_to_polish() {
+               return 'pl_PL';
+       }
+
+       /**
+        * @ticket 53238
+        */
+       function test_translate_settings_using_i18n_schema() {
+               $textdomain = 'notice';
+
+               add_filter( 'locale', array( $this, 'filter_set_locale_to_polish' ) );
+               load_textdomain( $textdomain, WP_LANG_DIR . '/plugins/notice-pl_PL.mo' );
+
+               $i18n_schema = (object) array(
+                       'title'    => 'block title',
+                       'keywords' => array( 'block keyword' ),
+                       'styles'   => array(
+                               (object) array( 'label' => 'block style label' ),
+                       ),
+                       'context'  => (object) array(
+                               '*' => (object) array(
+                                       'variations' => array(
+                                               (object) array(
+                                                       'title'       => 'block variation title',
+                                                       'description' => 'block variation description',
+                                                       'keywords'    => array( 'block variation keyword' ),
+                                               ),
+                                       ),
+                               ),
+                       ),
+               );
+               $settings    = array(
+                       'title'    => 'Notice',
+                       'keywords' => array(
+                               'alert',
+                               'message',
+                       ),
+                       'styles'   => array(
+                               array( 'label' => 'Default' ),
+                               array( 'label' => 'Other' ),
+                       ),
+                       'context'  => array(
+                               'namespace' => array(
+                                       'variations' => array(
+                                               array(
+                                                       'title'       => 'Error',
+                                                       'description' => 'Shows error.',
+                                                       'keywords'    => array( 'failure' ),
+                                               ),
+                                       ),
+                               ),
+                       ),
+               );
+               $result      = translate_settings_using_i18n_schema(
+                       $i18n_schema,
+                       $settings,
+                       $textdomain
+               );
+
+               unload_textdomain( $textdomain );
+               remove_filter( 'locale', array( $this, 'filter_set_locale_to_polish' ) );
+
+               $this->assertSame( 'Powiadomienie', $result['title'] );
+               $this->assertSameSets( array( 'ostrzeżenie', 'wiadomość' ), $result['keywords'] );
+               $this->assertSame(
+                       array(
+                               array(
+                                       'label' => 'Domyślny',
+                               ),
+                               array(
+                                       'label' => 'Inny',
+                               ),
+                       ),
+                       $result['styles']
+               );
+               $this->assertSame(
+                       array(
+                               array(
+                                       'title'       => 'Błąd',
+                                       'description' => 'Wyświetla błąd.',
+                                       'keywords'    => array( 'niepowodzenie' ),
+                               ),
+                       ),
+                       $result['context']['namespace']['variations']
+               );
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/l10n/translateSettingsUsingI18nSchema.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitteststhemewpThemeJsonResolverphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php   2021-08-10 21:13:38 UTC (rev 51598)
+++ trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php     2021-08-11 09:06:31 UTC (rev 51599)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -47,53 +47,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 52991
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_fields_are_extracted() {
-               $actual = WP_Theme_JSON_Resolver::get_fields_to_translate();
-
-               $expected = array(
-                       array(
-                               'path'    => array( 'settings', 'typography', 'fontSizes' ),
-                               'key'     => 'name',
-                               'context' => 'Font size name',
-                       ),
-                       array(
-                               'path'    => array( 'settings', 'color', 'palette' ),
-                               'key'     => 'name',
-                               'context' => 'Color name',
-                       ),
-                       array(
-                               'path'    => array( 'settings', 'color', 'gradients' ),
-                               'key'     => 'name',
-                               'context' => 'Gradient name',
-                       ),
-                       array(
-                               'path'    => array( 'settings', 'color', 'duotone' ),
-                               'key'     => 'name',
-                               'context' => 'Duotone name',
-                       ),
-                       array(
-                               'path'    => array( 'settings', 'blocks', '*', 'typography', 'fontSizes' ),
-                               'key'     => 'name',
-                               'context' => 'Font size name',
-                       ),
-                       array(
-                               'path'    => array( 'settings', 'blocks', '*', 'color', 'palette' ),
-                               'key'     => 'name',
-                               'context' => 'Color name',
-                       ),
-                       array(
-                               'path'    => array( 'settings', 'blocks', '*', 'color', 'gradients' ),
-                               'key'     => 'name',
-                               'context' => 'Gradient name',
-                       ),
-               );
-
-               $this->assertSame( $expected, $actual );
-       }
-
-       /**
-        * @ticket 52991
-        */
</del><span class="cx" style="display: block; padding: 0 10px">         public function test_translations_are_applied() {
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'locale', array( $this, 'filter_set_locale_to_polish' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                load_textdomain( 'block-theme', realpath( DIR_TESTDATA . '/languages/themes/block-theme-pl_PL.mo' ) );
</span></span></pre>
</div>
</div>

</body>
</html>