[wp-trac] [WordPress Trac] #60597: Script Modules API: Allow list of enqueued module data to be exposed
WordPress Trac
noreply at wordpress.org
Thu Apr 30 04:59:00 UTC 2026
#60597: Script Modules API: Allow list of enqueued module data to be exposed
--------------------------------------+--------------------------
Reporter: johnbillion | Owner: westonruter
Type: enhancement | Status: assigned
Priority: normal | Milestone: 7.1
Component: Script Loader | Version: 6.5
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+--------------------------
Comment (by peterwilsoncc):
In [changeset:"62286" 62286]:
{{{
#!CommitTicketReference repository="" revision="62286"
I18N: Add translation support for script modules.
Add automatic translation loading for script modules (ES modules), so
strings using `__()` and friends from `@wordpress/i18n` can be translated
at runtime. This brings classic script i18n parity to script modules
registered via `wp_register_script_module()`, which previously had no way
to load translation data, leaving strings untranslated on screens like
Connectors and Fonts that are built as script modules.
At the `admin_print_footer_scripts` and `wp_footer` actions, every
enqueued script module and its dependencies are walked, the translation
chunk is loaded for each, and an inline `<script>` calls
`wp.i18n.setLocaleData()` so translations are available before deferred
modules execute. Note there is currently a runtime dependency on the `wp-
i18n` classic script, which is printed just-in-time if not already
enqueued. This coupling is to be removed in a future release.
Public API:
* `WP_Script_Modules::set_translations()` stores the text domain (and
optional path) per registered module to override the text domain and path.
A global `wp_set_script_module_translations()` function is added as a
wrapper around `wp_script_modules()->set_translations()`.
* `WP_Script_Modules::get_registered()` obtains a registered module's
data. See #60597.
* `WP_Script_Modules::print_script_module_translations()` emits inline
`wp.i18n.setLocaleData()` calls after classic scripts load but before
modules execute.
* `load_script_module_textdomain()` loads the translation data for a given
script module ID and text domain.
* The existing `load_script_textdomain_relative_path` filter gains a third
`$is_module` parameter so callers can distinguish classic-script and
script-module lookups when resolving translation paths.
PHPStan types are also added in `WP_Script_Modules`. See #64238.
Developed in https://github.com/WordPress/wordpress-develop/pull/11543
Reviewed by audrasjb.
Merges r62278 to the 7.0 branch.
Props manzoorwanijk, westonruter, jsnajdr, jonsurrell, mukesh27,
peterwilsoncc, 369work, desrosj, sabernhardt, nilambar, jorgefilipecosta,
malayladu.
See #64238, #60597.
Fixes #65015.
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/60597#comment:27>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list