Fix JS translation loading and make all text translatable#582
Conversation
User-facing strings in several experiments were rendered without translation functions, so they could never be localized and were invisible to the i18n string scanner. Wrap toxicity/sentiment labels, badge states, error notices, and JSON validation messages with __(). In the Abilities Explorer help tab, each provider description was split into two translatable strings joined by a literal "<strong>" and ": ". This prevents translators from reordering the markup for their language. Make the whole sentence one translatable string with the <strong> tag inside, escaped via wp_kses. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The "Valid" and "Validation Errors" status labels were hardcoded, leaving them untranslatable. Wrap them with __() so they are exposed for localization like the surrounding validation messages. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Strings in JS/TS files were wrapped with @wordpress/i18n functions, but without wp_set_script_translations they were never localized at runtime and always rendered in English. Call it for every enqueued script so the translation JSON is loaded. No path is passed because the plugin is distributed on WordPress.org, which auto-delivers translations to wp-content/languages/plugins/. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Use self::HANDLE_PREFIX . $handle directly instead of the $script_handle local variable, since it was only used in straightforward calls. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Remove extra alignment whitespace left after a previous handle change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The error notice string fits within the line-length limit, so the multi-line wrapping is unnecessary. Match the formatting used by the other __() calls in the file. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
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. |
Since enqueue_script() now calls wp_set_script_translations(), every enqueued script gains wp-i18n as a dependency. The test expecting empty deps now fails because wp-i18n is appended even when the asset file omits dependencies. Adjust the assertion and rename the test to reflect what it actually verifies: enqueue succeeds for a dependency-less asset file. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| // wp_set_script_translations() appends wp-i18n to the otherwise empty deps. | ||
| $this->assertSame( array( 'wp-i18n' ), wp_scripts()->registered['ai_no-deps']->deps ); |
There was a problem hiding this comment.
This change is correct, but I'm not entirely confident. There might be a more reasonable way to assert this.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #582 +/- ##
=============================================
- Coverage 71.41% 71.41% -0.01%
Complexity 1158 1158
=============================================
Files 67 67
Lines 5584 5586 +2
=============================================
+ Hits 3988 3989 +1
- Misses 1596 1597 +1
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:
|

What?
Fixes internationalization (i18n) gaps across several experiments so that user-facing text is fully translatable.
Why?
Three problems were found:
@wordpress/i18nfunctions, butwp_set_script_translations()was never called for any enqueued script. As a result every JS-side string rendered in English regardless of the site locale.<strong>tag and": ". Translators could not see the full sentence and could not reorder the markup for their language.How?
wp_set_script_translations()for every script enqueued throughAsset_Loader::enqueue_script(). No path is passed because the plugin is distributed on WordPress.org, which auto-delivers translation JSON towp-content/languages/plugins/.<strong>tag inside, escaped withwp_kses()instead ofesc_html__().__().Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.7
Used for: Auditing the codebase for i18n issues and drafting the fixes. All changes were reviewed and verified by me.
Testing Instructions
ja) locale and make sure the plugin's Japanese translations are installed.Screenshots
Before
After
Changelog Entry