-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show translated strings coming from global styles variations #39960
Conversation
20fd0ad
to
ba83d4e
Compare
Note this needs the code to be ported to 6.0 to make sure we still load the schema file when the minimum WordPress version for the plugin is 5.9.
ba83d4e
to
b94824f
Compare
foreach ( $nested_html_files as $path => $file ) { | ||
$decoded_file = wp_json_file_decode( $path, array( 'associative' => true ) ); | ||
if ( is_array( $decoded_file ) ) { | ||
$translated = static::translate( $decoded_file, wp_get_theme()->get( 'TextDomain' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key point of this PR is this line: passing the decode JSON to translate
. The rest of the code remains the same as it was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_style_variations
had to be moved here to use translate
, which is not a public method of the WP_Theme_JSON_Resolver_Gutenberg
class.
Alternatively, we could make translate
public and use it in the rest API. Though I think this approach is better because it encapsulates all the logic for consumers: they just want to read the style variations.
* Default 'default'. | ||
* @return array Returns the modified $theme_json_structure. | ||
*/ | ||
protected static function translate( $theme_json, $domain = 'default' ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is not modified with respect to WP_Theme_JSON_Resolver_5_9::translate
, though it needs to live here to read the theme-i18n.json
from the lib/compat/6.0
folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense
Follow-up to #39322
What?
This PR shows the translated strings of the global styles variations according to the language of the user.
Why?
Style variations can contain strings that are shown to the user, such as the style variation title or the names of the presets (colors, font sizes, etc).
How?
WP_Theme_JSON_Resolver::get_style_variations
.translate
method we use for any othertheme.json
file.Testing Instructions
I've created a couple of style variations for the TwentyTwentyTwo theme and each contains the following translatable strings 1) the variation title and 2) one color in the color palette with a name. This is the result (I've set the screen to Spanish and so the expectation is that the variation title and the color defined by it should be translated):
style-variations-translated.mp4
Step by step, this is what I've done:
1 - Create the variations
styles/redish.json
with the following contents:styles/bluish.json
with the following contents:2 - Provide a translation
Unzip the
.mo
file I've created for TwentyTwentyTwo twentytwentytwo-es_ES.mo.zip atwp-content/languages/themes/
. This provides the strings of the style variations translated to Spanish.Alternatively, you can do this yourself by (expand to see how).
wp-content/languages/themes/
and paste the following at the end of thetwentytwentytwo-es_ES.po
file:wp i18n make-mo <path-to-your-po-file> <path-to-the-directory>
command to convert the.po
file into the.mo
one in the same directory.3 - Do the testing