Repository navigation
Script Modules: Fix missing translations of script modules - #84651
Draft
jorgefilipecosta wants to merge 6 commits into
Draft
jorgefilipecosta wants to merge 6 commits into
jorgefilipecosta wants to merge 6 commits into
Conversation
…ssic scripts depend on `WP_Script_Modules::print_script_module_translations()` only prints the translations of the enqueued script modules and their dependencies, so a script module that only a classic script imports through its `module_dependencies` loads with no translations. Its hooks are now replaced on `after_setup_theme`, right after WordPress adds them, with `gutenberg_print_script_module_translations()`, which also prints the translations of those script modules and of their dependencies. It only uses public methods, and prints each script module once whether or not WordPress includes the fix. A hook that was removed stays removed. The tests port the core cases, compare the output for the enqueued script modules with the one of WordPress, and cover the field modules that the Fields API adds to the `module_dependencies` of `wp-editor`.
…script modules
`gutenberg_override_translation_file()` only prepends the plugin slug to the translation files of the `wp-*` scripts. So the script modules that the plugin serves from its `build/` folder, e.g. from `build/modules/` and `build/routes/`, looked their translations up in `languages/plugins/{locale}-{md5}.json`, while the plugin language packs name these files `gutenberg-{locale}-{md5}.json`, and their strings stayed in English. These script modules now get the plugin translation file too.
…-page template The full-page template called the footer printers one by one, so it never printed the translations of the script modules, which WordPress prints on `admin_print_footer_scripts` since 7.0, and the strings of the script modules of full-page screens, like the extensible site editor, stayed in English. The footer now fires `admin_print_footer_scripts`, as `wp-admin/admin-footer.php` does. That prints the import map, the footer scripts, the script modules and their data and translations, in the order of the other admin pages, along with the late styles and the live regions of `@wordpress/a11y`, which the template missed too. WordPress hooks all of these printers to the action since 6.7, which the template already requires for `print_script_module_data()`.
…dules that classic scripts import The "Gutenberg Test Script Module Translations" test plugin adds a Tools page with two lines, each one written by a script module: one that the page enqueues, and one that only a classic script imports, declared in its `module_dependencies`. The plugin ships English translation files for both script modules, so each line ends with "(translated)" when its translations are printed, even on a site in English. Without the fix, only the first line is translated.
…t modules that classic scripts depend on
…s` in the full-page template
🤖 PR meta 🤖📦 Bundle sizeSize Change: 0 B Total Size: 8.58 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
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. refuses the drop and uploads nothing in
|
This was referenced Oct 13, 2026
Draft
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Core PR: WordPress/wordpress-develop#14260
Needed by #84643 and #83368.
Right now some strings of script modules show in English even when the language packs translate them:
module_dependencies, loads with no translations. Actions API: Extract the core actions into the@wordpress/core-actionsscript modules #84643 moves the DataViews core actions into script modules thatwp-editorimports this way, and Fields API #83368 does the same for the core fields. Their strings are translated today because they are bundled intowp-editor, so without a fix they would go back to English.languages/plugins/{locale}-{md5}.json, but the plugin language packs name these filesgutenberg-{locale}-{md5}.json. This already affects released screens, e.g. most of Settings > Connectors is in English.This PR:
WP_Script_Modules::print_script_module_translations()with a function that also prints the translations of the script modules that classic scripts depend on, and of their dependencies. It only uses public methods, and prints each script module once whether or not WordPress includes the fix from the core PR.gutenberg_override_translation_file()use the plugin translation files for the script modules served from the plugin'sbuild/folder too, as it does for the plugin's scripts.admin_print_footer_scripts, aswp-admin/admin-footer.phpdoes, instead of calling the footer printers one by one.Some notes:
get_registered().admin_print_footer_scriptssince 6.7, which the template already requires forprint_script_module_data(). Besides the translations, the full-page screens now also get the late styles and the live regions of@wordpress/a11y, and print the script modules before the classic scripts, like the other admin pages.@wordpress/core-actionsscript modules #84643 merged with this PR, in Portuguese (Portugal), with language pack files that move the strings of the core actions frombuild/scripts/editor/index.jsto thebuild/modules/core-actions/files, as GlotPress will once that PR ships. "Export as JSON" shows as "Exportar como JSON" in the pattern actions of the site editor only with the first two changes, and in the extensible site editor only with all three. Without them, the post editor prints no translations for the@wordpress/core-actionsscript modules either.Before
The test page of the e2e test, where one line comes from an enqueued script module and the other from a script module that only a classic script imports:
Settings > Connectors, in Portuguese (Portugal):
The extensible site editor, in Portuguese (Portugal), where the back link at the top of the sidebar comes from a script module:
After
Testing Instructions
Go through the steps on trunk first, then on this branch after
npm run build.Start the test environment with
npm run wp-env-test start.Save this snippet as
packages/e2e-tests/mu-plugins/module-translations-test.php, which the test environment loads as a must-use plugin. It registers atest/helloscript module that only a classic script imports, gives it a translation, and makes it show__( 'Hello' )in an alert on the Dashboard:Open http://localhost:8889/wp-admin/. On trunk, the alert says "Hello". With this PR, it says "Hello (translated)".
Install Portuguese (Portugal) and switch the admin user to it:
Open http://localhost:8889/wp-admin/options-general.php?page=options-connectors-wp-admin. On trunk, the title, the description, the AI plugin card and the note at the bottom are in English. With this PR, all of the page is in Portuguese.
Open http://localhost:8889/wp-admin/admin.php?page=site-editor-v2. On trunk, the back link at the top of the sidebar reads "Dashboard". With this PR, it reads "Painel".
Delete the snippet and switch the admin user back to English with
npm run wp-env-test -- run cli wp user meta delete admin locale. Then runnpm run test:unit:php:base -- --filter 'Gutenberg_Script_Module_Translations_Test|Override_Translation_File_Test|Tests_Fields_API'andnpm run test:e2e -- test/e2e/specs/admin/script-module-translations.spec.js.AI usage disclosure: fix and description drafted with AI assistance and reviewed by me.