-
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
Try: extract strings for translation directly from the source JSON file #28976
Conversation
names of strings to translate and contexts can contain spaces
What if the "Page title" string needs to use "," or anything else that could cause issues? |
Yeah. Is there a more robust format we can use for this? 🤔 |
I'm not aware of any. It's one of the reasons why we never went in this direction for |
Trying to create a format inside of a format is probably going to be a headache when it comes to proper sanitisation and escaping. How about leveraging the JSON format to "mark" certain properties with other properties? Rough example: "customTemplates": {
"page-home": {
"_x_title": "Context for this string",
"title": "Page title"
}
} The placement of |
Colocating metadata alongside the leaf node is an interesting idea. It addresses my main concern, which is how to express i18n in a way that grows with the evolution of theme.json and block.json and doesn't require changes to three different codebases (core, gutenberg, and wp-cli). Going to close this and focus on #28783 and/or prototyping that metadata colocation as next steps. |
To be fair, the current approach with a schema would not require changes to WP-CLI either. |
Yeah, I know. But it's proving difficult to generalize to things other than presets in ways that don't require the code to maintain some state as well 😣 I'll keep trying, though. |
This is an experiment to showcase an alternative approach to handle the translation of strings stored in JSON files.
Related:
block.json
block.json string extraction wp-cli/i18n-command#210theme.json
Extract translatable strings from theme.json files wp-cli/i18n-command#224#27380 introduced a way for extracting strings from theme.json for translation, based on the idea that having a shared intermediate file for core, gutenberg, and wp-cli would allow updating the theme.json structure without requiring changes to the code that process those strings.
Initially, the aim was to translate only presets. However,
theme.json
aims now to absorb more theme metadata that may need to be translated #28110 and information for translator context was added recently as well #28246 While working on adding support for translating thecustomTemplates
titles at #28783 I found the current direction too complex to implement with the current theme.json shape.This PR proposes an alternative: what if we marked the strings to translate directly in the source JSON file (block.json, theme.json) instead of having intermediate structures (code, i18.json file)? For familiarity, I used
_x( string-to-translate, context-for-translators )
but any mark could be used.For example, this would be a theme.json in which the color preset names and other fields are marked for translation:
This PR provides a prototype that implements this direction:
cc @swissspidy @schlessera @gziolo for thoughts.
How to test
test_get_template_parts
test.