close
Skip to content

Localize wp-build script module strings on the settings page#613

Merged
dkotter merged 1 commit into
WordPress:developfrom
t-hamano:fix/script-module-translations
May 26, 2026
Merged

Localize wp-build script module strings on the settings page#613
dkotter merged 1 commit into
WordPress:developfrom
t-hamano:fix/script-module-translations

Conversation

@t-hamano
Copy link
Copy Markdown
Contributor

@t-hamano t-hamano commented May 23, 2026

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 through Asset_Loader::enqueue_script(). That covers classic scripts, but the settings page and other wp-build routes are enqueued as script modules*, which wp_set_script_translations() does not apply to.

How?

Register the ai text domain for the route content script module via wp_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.0 ignoreErrors list.

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

  1. Switch the site to the Japanese (ja) locale and make sure the plugin's Japanese translations are installed.
  2. Access wp-admin/update-core.php and download any available translations.
  3. Open Settings → AI and confirm that strings are now displayed in Japanese.

Screenshots or screencast

Before

before

After

after

Changelog Entry

Fixed - Settings page strings, which are enqueued as script modules, are now localized at runtime.

Open WordPress Playground Preview

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
Copy link
Copy Markdown

codecov Bot commented May 23, 2026

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.16%. Comparing base (246680c) to head (6d25502).
⚠️ Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
includes/Settings/Settings_Page.php 33.33% 2 Missing ⚠️
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     
Flag Coverage Δ
unit 73.16% <33.33%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@t-hamano t-hamano marked this pull request as ready for review May 23, 2026 06:50
@github-actions
Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@dkotter dkotter merged commit 60cba5b into WordPress:develop May 26, 2026
29 of 32 checks passed
@dkotter dkotter added this to the 1.1.0 milestone May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants