Skip to content

Commit f8bd260

Browse files
committed
Script Modules: Merge translation overrides into \$registered.
Store the textdomain and translations_path for a script module directly on its entry in WP_Script_Modules::\$registered, rather than in a separate \$translations property. This mirrors how WP_Dependency stores those fields for classic scripts and keeps all data about a module in one place. The nested 'translations' key is only set when set_translations() is called for that module, so the 'optional override' intent is preserved.
1 parent 07fbf49 commit f8bd260

1 file changed

Lines changed: 7 additions & 17 deletions

File tree

src/wp-includes/class-wp-script-modules.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* dependencies: array<int, array{ id: string, import: 'static'|'dynamic' }>,
2020
* in_footer: bool,
2121
* fetchpriority: 'auto'|'low'|'high',
22+
* translations?: array{ textdomain: string, translations_path: string },
2223
* }
2324
*/
2425
class WP_Script_Modules {
@@ -90,17 +91,6 @@ class WP_Script_Modules {
9091
*/
9192
private $modules_with_missing_dependencies = array();
9293

93-
/**
94-
* Holds translation data for script modules, keyed by script module identifier.
95-
*
96-
* Each entry contains 'domain' and 'path' keys for the text domain
97-
* and the path to translation files respectively.
98-
*
99-
* @since 7.0.0
100-
* @var array<string, array{domain: string, path: string}>
101-
*/
102-
private array $translations = array();
103-
10494
/**
10595
* Registers the script module if no script module with that script module
10696
* identifier has already been registered.
@@ -369,9 +359,9 @@ public function set_translations( string $id, string $domain = 'default', string
369359
return false;
370360
}
371361

372-
$this->translations[ $id ] = array(
373-
'domain' => $domain,
374-
'path' => $path,
362+
$this->registered[ $id ]['translations'] = array(
363+
'textdomain' => $domain,
364+
'translations_path' => $path,
375365
);
376366

377367
return true;
@@ -396,9 +386,9 @@ public function print_script_module_translations(): void {
396386
$module_ids = $this->get_sorted_dependencies( $this->queue );
397387

398388
foreach ( $module_ids as $id ) {
399-
if ( isset( $this->translations[ $id ] ) ) {
400-
$domain = $this->translations[ $id ]['domain'];
401-
$path = $this->translations[ $id ]['path'];
389+
if ( isset( $this->registered[ $id ]['translations'] ) ) {
390+
$domain = $this->registered[ $id ]['translations']['textdomain'];
391+
$path = $this->registered[ $id ]['translations']['translations_path'];
402392
} else {
403393
$domain = 'default';
404394
$path = '';

0 commit comments

Comments
 (0)