Premium Analytics: say where each widget module's translations live - #52634
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! |
Code Coverage SummaryCoverage changed in 10 files. Only the first 5 are listed here.
|
e773f41 to
95fdf76
Compare
Nikschavan
left a comment
There was a problem hiding this comment.
Thank you, the changes look good. One small note on the testing steps: pnpm run test -- --testPathPatterns=widget-module-i18n exits with "No tests found" because pnpm passes the -- through to jest. pnpm run test --testPathPatterns=widget-module-i18n runs the 34 tests.
9b105a4 to
7ca9110
Compare
|
Good catch, pnpm forwards the |
5f0dce9 to
bf35ba1
Compare
textdomain and i18n_manifest per type; the client loads a plugin's widget catalogs from them
require default sections in the registry test, drop the version-shape test, fix the availability header
bf35ba1 to
3cc66f9
Compare
…52634) * add the catalog location to widget module records textdomain and i18n_manifest per type; the client loads a plugin's widget catalogs from them * apply the review follow-ups from #52568 require default sections in the registry test, drop the version-shape test, fix the availability header * mock the widget module resolver in the stage test
Fixes WOOA7S-2186
Proposed changes
Step 2 of 4 of the widget-type extensibility stack (umbrella: #52637). Step 1 (#52568) lets a plugin register widget types from its own build; this step lets the dashboard translate them.
What?
Every widget module record says where its bundles' translation catalogs live, and the client loads them from there.
Widget_Typegainstextdomain, the domain the widget's metadata and bundles are stamped with, andi18n_manifest, the URL of thei18n-manifest.jsonof the build that serves its modules./wpcom/v2/widget-modulespublishes both.register_widget_types_from_manifest( $widgets, $args )takes both in$argsas defaults for candidates that declare none.register_widget_type()accepts them like any other property.createWidgetModuleResolver( records )builds theresolveWidgetModulethe four dashboards hand toWidgetDashboard, through auseWidgetModuleResolver()hook. Before importing a module it caches its build's manifest, once per domain, and loads the bundle's catalog under the record's domain. The metadata (widget.js) preload does the same per record.loadI18nManifest( domain, url )inwp-build-polyfillscaches another build's manifest, the counterpart of whatloadI18nCatalogs()does for the page's own build at boot.{prefix}/widgets/{dir}/{render,widget}tobuild/widgets/{dir}/{render,widget}.js, not the package's alone.Why?
A plugin's widget bundles are stamped with the plugin's text domain and listed in the plugin's manifest, which the dashboard page never loads: boot loads the package's own manifest and nothing else. Without a record saying where its catalogs live, a plugin's widgets render in English. The first consumer is the Ads package, #52635.
How?
A record without a text domain, from an older server, is treated as the package's own, so nothing changes for the package's widgets. A domain already cached keeps its bundle set, whatever URL a later call names, and a manifest is published before it resolves, so a catalog load right after it waits rather than skips. The catalog load hashes the bundle path relative to the plugin, the way WordPress names JS translation files, so a package vendored inside a plugin keeps aliasing its text domain in the plugin's
i18n-map.php, as this package does.Docs come with step 4 (#52636).
Also carries the review follow-ups from #52568: the
widget-availability.phpheader now says the policy covers manifest candidates only, the registry test requiresdefault-dashboard-sections.phpitself, the version-shape test is gone, and the duplicate-name test asserts the type is still registered.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
A plugin's record
Add this mu-plugin. It registers the package's own Clicks bundles again under a
demo/module id, and a type on them under ademotext domain with the package's manifest, so it needs no build. Its own ids matter: the dashboard caches an imported render module by id, so a type that reusesjetpack-premium-analytics/widgets/clicks/renderwould reuse the import Clicks already made, catalog included.GET /wp-json/wpcom/v2/widget-modulesshowstextdomain: "demo"and the manifest URL ondemo/clicks. The package's own records (jpa/*) showtextdomain: "jetpack-premium-analytics-pkg"andi18n_manifest: null.wp language core install es_ES --activate;wp.jpI18nLoader.state.localein the console must not readen_US).Open the widget picker and add "Demo clicks" to a section.
The network tab shows, in this order:
i18n-manifest.jsonwp-content/languages/plugins/demo-es_ES-<md5>.jsonwidgets/clicks/render.min.js.No build ships a
democatalog, so the widget renders in English: a 404 is swallowed quietly, and a dev site that answers a missing file with a redirect to an HTML page logs a[jetpack-i18n] Failed to load "demo" catalogwarning instead.textdomaintojetpack-premium-analytics-pkgand reload. No manifest request this time: the domain is the page's own, cached at boot, and the catalog is the one the package's Clicks uses.Under
en_USnone of these requests happen, as before.