-
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
Add theme.json i18n mechanism and JSON file specifying which theme.json paths are translatable #27380
Merged
jorgefilipecosta
merged 4 commits into
master
from
add/json-file-exposing-the-translatable-paths-and-a-theme-json-translation-mechanism
Jan 12, 2021
+113
−0
Merged
Add theme.json i18n mechanism and JSON file specifying which theme.json paths are translatable #27380
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0b87506
Add JSON specifying which theme.json paths are translatable; theme.js…
jorgefilipecosta 03ceff9
Update lib/class-wp-theme-json-resolver.php
jorgefilipecosta 9afc5cd
Update lib/class-wp-theme-json-resolver.php
jorgefilipecosta 93c3c87
Not assume settings
jorgefilipecosta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
oandregal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"settings": { | ||
"typography": { | ||
"fontSizes": [ | ||
"name" | ||
], | ||
"fontStyles": [ | ||
"name" | ||
], | ||
"fontWeights": [ | ||
"name" | ||
], | ||
"fontFamilies": [ | ||
"name" | ||
], | ||
"textTransforms": [ | ||
"name" | ||
], | ||
"textDecorations": [ | ||
"name" | ||
] | ||
}, | ||
"color": { | ||
"palette": [ | ||
"name" | ||
], | ||
"gradients": [ | ||
"name" | ||
] | ||
} | ||
} | ||
} |
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.
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.
Is the plan to always keep a local copy of the file with the schema for translations? It usually gives us more flexibility when there is a hook introduced upfront. This way the filters let to add only new keys that need to be translated.
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.
Yes, the plan is for the file to always exist locally.
If we had a hook that allowed to add new keys to be translatable, wp-cli would not be aware of the hook and would not extract the strings anyway, so the strings would not be translatable anyway.
The keys that are translatable are something static like in https://github.com/WordPress/wordpress-develop/blob/d2c8fae049e80f5726653c61361d467fad1a8a0b/src/wp-admin/includes/plugin.php#L149-L194 a plugin can not add other $plugin_data keys to be translatable.
If a plugin wants to inject translatable information in the theme.json structure, the plugin would use the filters that allow to change the structure and do something like
$theme_json['settings'][mycustomPreset]= array( array( 'customPorperty' => __( 'translatable string' ) ) );
Given that it is done in code the string extraction would work as expected. So it would be possible for a plugin to inject translatable information using code not requiring to filter this file.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.
I'm sure that some sort of filter is going to be necessary. Once you have the definition of translatable fields in the WordPress core, you might end up willing to expand it in Gutenberg when a new section is added to
theme.json
file. You can always simply overrideexperimental-i18n-theme.json
in Gutenberg and call it the day, but we should account for that when backporting logic to the WP core 😄