From 3af54e5bb81d85b8a88d9417c35bc4df6a243a25 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Tue, 10 Nov 2026 23:47:54 +0000 Subject: [PATCH 1/2] I18N: Print translations for the script modules that scripts depend on. `WP_Script_Modules::print_script_module_translations()` only covered the enqueued script modules and their dependencies. A script module that only a script imports, declared in the script's `module_dependencies`, is added to the import map and loads, but its translations were never printed, so its strings showed untranslated. The method now covers the enqueued script modules and the script modules in the import map, which includes the script module dependencies of scripts and their dependencies. `WP_Script_Modules::print_script_module_data()` already covered these script modules, and both methods now get them from the same private `get_loadable_script_module_ids()` method, which sorts them with `get_sorted_dependencies()`. This way both methods always cover the same script modules, in the same order, with dependencies before the script modules that depend on them. A script module that is both enqueued and imported by a script gets its translations printed once. Since the import map is now built three times per page, a missing script module dependency of a script triggers the `_doing_it_wrong()` notice once per script. Fixes #66591. --- src/wp-includes/class-wp-script-modules.php | 65 +++- .../tests/script-modules/wpScriptModules.php | 312 ++++++++++++++++++ 2 files changed, 360 insertions(+), 17 deletions(-) diff --git a/src/wp-includes/class-wp-script-modules.php b/src/wp-includes/class-wp-script-modules.php index 180b42362db1a..31e72469a02fd 100644 --- a/src/wp-includes/class-wp-script-modules.php +++ b/src/wp-includes/class-wp-script-modules.php @@ -92,6 +92,18 @@ class WP_Script_Modules { */ private $modules_with_missing_dependencies = array(); + /** + * List of handles for scripts encountered which have missing script module dependencies. + * + * A handle is added to this list when it is discovered to have script module dependencies that are not + * registered. At this time, a warning is emitted with {@see _doing_it_wrong()}. The handle is then added to this + * list, so that duplicate warnings don't occur. + * + * @since 7.2.0 + * @var string[] + */ + private $scripts_with_missing_module_dependencies = array(); + /** * Registers the script module if no script module with that script module * identifier has already been registered. @@ -367,7 +379,8 @@ public function set_translations( string $id, string $domain = 'default', string } /** - * Prints translations for all enqueued script modules. + * Prints translations for the enqueued script modules and for the script + * modules in the import map. * * Outputs inline `