Show translated strings coming from global styles variations #39960
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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