Repository navigation
Premium Analytics: emit gettext stubs for the widget.json strings - #53850
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 1 file.
3 files are newly checked for coverage.
|
dognose24
left a comment
There was a problem hiding this comment.
LGTM. The emitter mirrors what the registry does at hydration, so the (msgid, msgctxt, domain) triples it writes are the ones the lookups will ask for.
What I checked:
walkSchemaagainst core'stranslate_settings_using_i18n_schema(): string leaf, list viaschema[0], keyed map with the*fallback, empty strings skipped.attributesandelementsare lists in bothwidget.jsonand the schema, and the six contexts are the onestranslate_widget_metadata()uses.- Domains line up: the ads, VideoPress and WooCommerce Stats manifests all declare
textdomain, and the Premium Analytics ones fall back toextra.textdomain, the same fallbackregister_widget_types_from_manifest()applies. - The stub lands in
build/widgets/, which every one of the four packages marksproduction-include, so it ships the way the JS i18n stubs fromstrip-unminified-prodalready do and reaches the same extraction. - Single-quoted PHP escaping covers exactly
\and'; a run with nothing to emit removes a stale stub;--schema,--widgets,--out,--domainare all exercised by the bin tests against the real executable. stamp-textdomainskeeps its behaviour through the shared resolver.
One thing to add before merging: a plugins/premium-analytics changelog entry (inline). Two optional notes inline.
| Significance: patch | ||
| Type: bugfix | ||
|
|
||
| Premium Analytics: Make widget titles, descriptions, help notes and settings labels translatable. |
There was a problem hiding this comment.
plugins/premium-analytics bundles both premium-analytics and woocommerce-stats, and translated widget metadata is something its users notice, so it wants an entry too (no product prefix there). plugins/videopress does not: Top videos only renders inside the Premium Analytics dashboard, which that plugin does not ship.
There was a problem hiding this comment.
Added in 008a6e2, fixed and no prefix. Agreed on plugins/videopress: nothing there reaches the widget.
| /** | ||
| * Library for the `emit-widget-strings` bin. | ||
| * | ||
| * wp-build copies each widget's `widget.json` metadata into | ||
| * `build/widgets/registry.php` as plain literals, and the widget registry | ||
| * translates them at hydration with `_x( value, context, domain )`, the | ||
| * contexts coming from the widget i18n schema (`widget-i18n.json`). No | ||
| * extractor reads either file, so on their own the (msgid, msgctxt) pairs | ||
| * never reach a catalog: `wp i18n make-pot` knows `block.json` natively, | ||
| * `widget.json` not yet. This emits a PHP file nothing loads, holding one | ||
| * `_x()` per value with the exact context and domain the registry will look | ||
| * up, the way core's `wp-admin/includes/continents-cities.php` exists for | ||
| * gettext alone. | ||
| */ |
There was a problem hiding this comment.
Optional: this header, the bin header, the README section and dashboard-widgets.md are four copies of the same explanation. One sentence here plus a pointer to the README keeps it within the comment budget, and leaves a single place to update when wp i18n make-pot learns widget-i18n.json.
There was a problem hiding this comment.
Trimmed in b7d2b3c: the README owns the explanation and the flag defaults; the lib and bin headers keep one sentence and a pointer, and the Premium Analytics doc names the lane and points at the README.
| it( 'covers every Premium Analytics widget with contexts the schema names', () => { | ||
| const { entries, widgets } = collectWidgetStrings( | ||
| path.join( PA_DIR, 'widgets' ), | ||
| SCHEMA, | ||
| 'jetpack-premium-analytics-pkg' | ||
| ); | ||
| const contexts = new Set( schemaContexts( SCHEMA ) ); | ||
| const titles = entries.filter( entry => entry.context === 'widget title' ); | ||
| assert.ok( widgets > 0 ); | ||
| assert.equal( titles.length, widgets, 'one title per widget' ); | ||
| assert.ok( entries.every( entry => contexts.has( entry.context ) ) ); | ||
| assert.ok( entries.every( entry => entry.domain === 'jetpack-premium-analytics-pkg' ) ); | ||
| } ); |
There was a problem hiding this comment.
Optional: this ties the wp-build-polyfills suite to Premium Analytics' widgets/ layout and schema path. Fine inside the monorepo, just worth knowing that a Premium Analytics reshuffle will fail here first.
There was a problem hiding this comment.
Decoupled in b771bb5: the suite uses an inline schema fixture with every shape the walk handles, and the sync check against the Premium Analytics tree is gone. Two of its assertions restated the inputs, and "one title per widget" is that package's invariant, not the emitter's.
lib, bin and PA docs keep one sentence and a pointer
an inline schema fixture replaces the Premium Analytics sync check
Part of WOOA7S-2175 (WOOA7S-2174, task T0.1).
Proposed changes
The widget.json strings reach a catalog
Every widget title, description, help note, and settings label declared in
widget.jsonrenders in English in every locale.wp-buildcopies them intobuild/widgets/registry.phpas plain literals, and the registry translates them at hydration with_x( value, context, domain ), the contexts coming fromsrc/widget-i18n.json.But no extractor reads
widget.jsonorregistry.php(wp i18n make-potknowsblock.json, notwidget.json), so the (msgid, msgctxt) pairs never reach a catalog and every lookup misses.emit-widget-strings, a new bin inwp-build-polyfillsnext tostamp-textdomains, walks everywidgets/*/widget.jsonin lockstep with the schema and writesbuild/widgets/widget-strings.php: one_x()per translatable value, with the exact context the registry looks up and the widget's text domain, or the package'sextra.textdomainfor a widget that declares none.Nothing loads the file; it exists for gettext extraction, like core's
wp-admin/includes/continents-cities.php.Once a catalog carries the strings, the registry's lookups succeed and the REST record arrives translated; the client changes nothing.
Premium Analytics, WooCommerce Stats, Ads and VideoPress run it after
wp-build. The three consumer packages point it at this package's schema, which their widgets are translated with.stamp-textdomainsshares the new text-domain resolver.Upstream, WordPress/gutenberg#80564 proposes the same file for the Gutenberg plugin's own widgets as a private build step, and native
wp i18n make-potsupport waits forwidget-i18n.jsonto reach core. The bin goes the day it ships for consumers.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Clean
Build
Each package now has
build/widgets/widget-strings.php, one_x()per line: 143 in Premium Analytics, 90 in WooCommerce Stats, 13 in Ads, 4 in VideoPress.php -lpasses on each.Premium Analytics
WooCommerce Stats
VideoPress
Ads
Extraction
In
projects/packages/premium-analytics, this yields 143 entries, each with itsmsgctxt:widget title,widget description,widget help content,widget help link label,widget attribute label,widget attribute option label.Example:
Translation
Translations arrive with the first translate.wordpress.org import of a release that ships the stub, so a local check needs a hand-made catalog: a
.powith amsgctxt "widget title"entry for one title,wp i18n make-mo, the.modropped intowp-content/languages/plugins/under the plugin's domain (jetpack-<locale>.mo, the aliasi18n-map.phpdeclares), the site switched to that locale.GET /wp-json/wpcom/v2/widget-modulesthen returns that title translated, and so does the dashboard.Tests
pnpm run testinprojects/packages/wp-build-polyfills.