Repository navigation
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: 0 B Total Size: 7.75 MB |
|
#79701 landed the runtime side of widget metadata translation and left string extraction pending, as noted in #77629 (comment): That native support remains the endgame once the format stabilizes; this generated file bridges the window by emitting the same (msgid, msgctxt, textdomain) triples a native extractor would produce from |
|
Flaky tests detected in 6c2f330. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29936561294
|
| ); | ||
|
|
||
| if ( calls.length === 0 ) { | ||
| return; |
There was a problem hiding this comment.
I wonder if it would be worth removing an existing widget-strings.php before returning here. Otherwise, after the last textdomain or translatable value is removed, strings from an earlier build could remain in the generated POT.
| generateRoutesRegistry( activeRoutes, phpReplacements ), | ||
| generateRoutesPhp( activeRoutes, phpReplacements ), | ||
| generateWidgetRegistry( widgets, phpReplacements ), | ||
| generateWidgetStrings( widgets, phpReplacements ), |
There was a problem hiding this comment.
Would it make sense to regenerate the widget registry and strings file when widget.json changes in watch mode too?
There was a problem hiding this comment.
Yes, it could be, but I'd like teo consider it in a separate PR. This change is out of scope for this PR.
| 'experimental', | ||
| 'dashboard-widgets', | ||
| 'widget-i18n.json' | ||
| ); |
There was a problem hiding this comment.
I’m wondering whether this sync check might fit better on the Gutenberg/dashboard-widgets side. That would help keep the generic @wordpress/build tests independent of Gutenberg’s internal lib/experimental directory structure.
| - `build/widgets/{widget-name}/widget.min.js` + `widget.js` — Bundled metadata (ESM) | ||
| - `build/widgets/{widget-name}/widget.min.asset.php` — Asset metadata for widget module | ||
| - `build/widgets/registry.php` — Widget registry data | ||
| - `build/widgets/widget-strings.php` — Gettext calls for the translatable `widget.json` metadata, for extraction tooling; never loaded at runtime. Generated when a widget declares a `textdomain`. |
There was a problem hiding this comment.
Tiny nit: because the domain may also come from wpPlugin.textdomain, perhaps this could say:
Generated when at least one widget has a resolved textdomain and a translatable metadata value.?
| ...schema.help.links.map( ( link ) => link.label ), | ||
| ...schema.actions.map( ( action ) => action.label ), | ||
| ...schema.keywords, | ||
| ].sort(); |
There was a problem hiding this comment.
I like the schema-drift check here. I wonder if collecting the schema’s string leaves recursively would make it a little more future-proof. With the current explicit paths, a newly added field such as subtitle could be omitted from both this list and the extractor while the test still passes.
|
How do we do this for block.json, theme.json and things like that? |
The If For experimental/unstable file types, generating an auxiliary PHP file is a good idea. But keep in mind that the name of the file that a string was extracted from is an integral part of the translation string definition, and will be used when producing a set of translations files that are loaded at runtime. Who and when loads the |
This is my issue with this PR, It adds an API and updates wp-build for something we know is not the final desired result. |
Can we then move the functionality outside |
|
After looking at the approach as a whole, I'm not sure what the logical next step is. In fact, I'm not sure we're in a position to tackle the translation problem at all, given how experimental and in active development the Widgets API still is. Two things do seem clear to me:
We can clean the changes out of But I wonder now whether it's worth it for an experimental feature, since in the worst case the translatable widget metadata simply renders untranslated. Also, if we want to see these strings actually getting translated now, the bundled widgets would have to use the Yes @jsnajdr. The goal is that consumers/plugins can declare widget metadata in their JSON files and have the framework take care of the whole pipeline, translation included. As with other pieces of this implementation, in the meantime third-party developers will have to roll their own local, temporary implementations, along the lines of the private script this PR adds. For now the PR stands as:
Something to keep analyzing.
The build compiles it into It doesn't participate in any runtime lookup. |
|
Thanks, @chihsuan. I've changed the approach by removing the code from wp-build. More in the comment above. |
bfa1b10 to
e5282f1
Compare
🤖 PR meta 🤖📦 Bundle sizeSize Change: 0 B Total Size: 8.21 MB
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
|
What?
Adds a private build step that generates
build/widgets/widget-strings.php, with one_x()call per translatablewidget.jsonmetadata value (title,description,help.content,help.links[].label,actions[].label,keywords[]). The file is never loaded at runtime; it exists so gettext extraction tooling sees the strings.Following the review discussion, the generation lives in the repo's private build scripts (
tools/build-scripts/);wp-buildis untouched.The bundled widgets also switch their
textdomainfromdefaulttogutenberg, so the strings can reach the plugin translation project on wp.org before the feature lands in core.Fixes #80561.
Related to #77629
Why?
The runtime translation pipeline already exists:
gutenberg_translate_widget_metadata()translates the hydrated registry oninitthroughtranslate_settings_using_i18n_schema()with the contexts inlib/experimental/dashboard-widgets/widget-i18n.json.But the strings never reach a catalog:
registry.phpcarries plain literals, and no extraction tooling understandswidget.json(unlikeblock.json, whichwp i18n make-potand the wp.org importer support natively). So widget metadata renders untranslated in every non-English locale, including the widgets bundled in this repo.Native
make-potsupport is the endgame once the format stabilizes; this generated file bridges the window with the same (msgid, msgctxt, textdomain) triples a native extractor would produce, so it can be deleted then without changing the resulting POT.How?
tools/build-scripts/packages/generate-widget-strings.mjs, invoked fromtools/build-scripts/build.mjsright after thewp-buildstep, with agenerate-widget-stringsalias in the workspacepackage.json.widget.jsonin lockstep withwidget-i18n.json, mirroring thetranslate_settings_using_i18n_schema()traversal the runtime uses. There is no duplicated context map to keep in sync.textdomainare skipped, matching the runtime no-op. Entries are deduplicated per (value, context, textdomain) and escaped as single-quoted PHP literals.widget-strings.phpis removed, so stale strings never linger in a POT.widget.jsonfiles declare"textdomain": "gutenberg": withdefault, the plugin translation project filters the strings out, and core catalogs carry no entries for these context-qualified lookups.Testing Instructions
node tools/build-scripts/packages/generate-widget-strings.mjs(it also runs as part ofnpm run build).build/widgets/widget-strings.php: one_x()per metadata value:build/widgets.phponly requiresregistry.phpand the per-widget asset files.wp i18n make-pot build/widgets widgets.pot --ignore-domainand confirm the strings appear, with their contexts, in the generated POT.textdomaininwidgets/*/widget.json, re-run the emitter, and confirm the generated file is deleted; restore withgit checkout -- widgets.Follow-ups
widget.jsonextraction towp-cli/i18n-commandonce the metadata format stabilizes, and remove this build step.