-
Notifications
You must be signed in to change notification settings - Fork 52
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
Extract translatable strings from theme.json files #224
Comments
Thanks for opening this, @jorgefilipecosta! How far advanced is the work on this? I hesitate a bit to add this as long as it's still experimental. Also, is there a JSON schema for what the You mention |
Hi @swissspidy,
We already have a very concrete idea of the strings that should be translatable. We may need to add more translatable keys in the future. But I guess it will not be hard to add more keys. We don't have a schema but I guess we can specify what settings are translable using something like:
Or we can even assume only presets are translatable and what is translatable is the name and we can represent translatable presets as: Regarding the theme.json structure at the top level, we have an object whose keys are selectors:
A selector can be "global" applies styles and settings to the root of the website, a block identifier, e.g.: "core/paragraph", or a custom selector defined by the block for blocks supporting multiple selectors like "core/heading/h1". Inside the object of each selector, we have "styles" and "settings".
Styles don't need any translation, while the settings may need. Inside each settings object, we have a group of settings e.g.:
Some of the settings can be translatable like all the following names:
The translatable files are:
There is no difference in the shape of theme.json and default-theme.json. They are the same thing. The default-theme.json contains the WordPress theme.json default file. Let me know if there is anything that is not clear regarding what part of theme.json files are translatable. And thank you for looking into this issue @swissspidy! |
Thanks for the update @jorgefilipecosta! Sounds straightforward enough to be able to put together a first working version of this. |
Thank you @swissspidy, would you be able to work on the first version? |
@jorgefilipecosta The above We don't need a full-blown schema for this, but the discovery itself needs to be part of WordPress Core in some shape. For a very simple solution, can we have the above information as a JSON file updated and shipped with WordPress Core (can be in any subfolder as long as we can tell WP-CLI where to look for it): {
"typography": {
"fontSizes": [
"name"
],
"fontFamilies": [
"name"
]
},
"color": {
"palette": [
"name"
],
"gradients": [
"name"
]
}
} As soon as we have something like this within WordPress Core, you can change the strings around as much as you want (provided you update the above file), and WP-CLI will always work with the latest and greatest changes without any modifications at all. |
@schlessera Is core the right place? String extraction currently works without requiring a WP installation and I don't think this should be changed. So if all I have is a theme folder, how would WP-CLI know where to find the file? Should there be a cached copy bundled with the command? Does the user need to provide the path to it? |
@swissspidy If we know where the file is located, we can always download the latest version of the file as needed. This is not necessarily about having it available at the currently used installation, it's more about having it be versioned together with Core releases, and WP-CLI just using whatever is the latest version. |
I'm trying the approach of exposing a file that contains translatable paths in WordPress/gutenberg#27380. If we merge it to Gutenberg the file should make its way into the core during the next core Gutenberg update. |
Let's follow the same approach for |
👋 There were recent changes to the theme.json format and more things need to be translated. I was trying to add a translation for a new field that wasn't a preset (it lived in a different subtree) at WordPress/gutenberg#28783 During that process, I realized a potentially simpler way to extract strings for translation in JSON files: 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)? I implemented this at WordPress/gutenberg#28976 as a prototype for you all to look at. Would love your thoughts over there. |
Feature Request
Describe your use case and the problem you are facing
For supporting the next generation of themes, we need to extract strings from theme.json files.
Describe the solution you'd like
wp i18n make-pot should parse theme.json files and extract all strings it finds with the additional context.
Sample file:
In all these cases "name" should be translatable.
For now, these files are named experimental-theme.json (future theme.json) on WordPress themes, and experimental-default-theme.json (future default-theme.json) for the core own default file.
It is very related to the work done for block.json #210.
The text was updated successfully, but these errors were encountered: