Localize wp-build script module strings on the settings page#613
Conversation
Pages built by wp-build (e.g. the AI settings page) enqueue their JS as script modules. wp_set_script_translations() only applies to classic scripts, so route JS strings such as "Enable AI" stayed untranslated even though correctly named JSON translation files were present. Register the `ai` text domain for the route content module via wp_set_script_module_translations() (WordPress 7.0+) so those strings are localized. Also ignore the not-yet-stubbed function in PHPStan, matching the existing handling of other WP 7.0 functions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #613 +/- ##
=============================================
- Coverage 73.18% 73.16% -0.02%
- Complexity 1731 1732 +1
=============================================
Files 85 85
Lines 7473 7476 +3
=============================================
+ Hits 5469 5470 +1
- Misses 2004 2006 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
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. |

What?
Follow up to #582
Localize the JS strings on the settings page, which were still rendered in English even after #582.
Why?
#582 fixed JS translation loading by calling
wp_set_script_translations()for every script enqueued throughAsset_Loader::enqueue_script(). That covers classic scripts, but the settings page and otherwp-buildroutes are enqueued as script modules*, whichwp_set_script_translations()does not apply to.How?
Register the
aitext domain for the route content script module viawp_set_script_module_translations(). For the background of this function's addition, please refer to https://core.trac.wordpress.org/ticket/65015#comment:45.PHPStan does not yet ship a stub for
wp_set_script_module_translations(), so it is added to the existing WP 7.0ignoreErrorslist.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.7
Used for: Tracing the script module i18n path through WordPress core and drafting the fix. All changes were reviewed and verified by me.
Testing Instructions
ja) locale and make sure the plugin's Japanese translations are installed.wp-admin/update-core.phpand download any available translations.Screenshots or screencast
Before
After
Changelog Entry