I18N: Set translations for all WordPress packages scripts.
Calls `wp_set_script_translations` for all packages scripts that have translations. Also correctly sets the domain on the translations. Props omarreiss, pento, ocean90. Merges [43878] to trunk. Fixes #45161. git-svn-id: https://develop.svn.wordpress.org/trunk@44239 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c687f1957e
commit
a10598acd0
@ -546,7 +546,8 @@ class WP_Scripts extends WP_Dependencies {
|
||||
}
|
||||
|
||||
$output = '(function( translations ){' .
|
||||
'wp.i18n.setLocaleData( translations.locale_data, "' . $domain . '" );' .
|
||||
'translations.locale_data.messages[""].domain = "' . $domain . '";' .
|
||||
'wp.i18n.setLocaleData( translations.locale_data.messages, "' . $domain . '" );' .
|
||||
'})(' . $json_translations . ');';
|
||||
|
||||
if ( $echo ) {
|
||||
|
@ -319,7 +319,7 @@ function wp_default_packages_scripts( &$scripts ) {
|
||||
'html-entities' => array( 'wp-polyfill' ),
|
||||
'i18n' => array( 'wp-polyfill' ),
|
||||
'is-shallow-equal' => array( 'wp-polyfill' ),
|
||||
'keycodes' => array( 'lodash', 'wp-polyfill' ),
|
||||
'keycodes' => array( 'lodash', 'wp-polyfill', 'wp-i18n' ),
|
||||
'list-reusable-blocks' => array(
|
||||
'lodash',
|
||||
'wp-api-fetch',
|
||||
@ -361,11 +361,28 @@ function wp_default_packages_scripts( &$scripts ) {
|
||||
'wordcount' => array( 'wp-polyfill' ),
|
||||
);
|
||||
|
||||
$package_translations = array(
|
||||
'api-fetch' => 'default',
|
||||
'blocks' => 'default',
|
||||
'block-library' => 'default',
|
||||
'components' => 'default',
|
||||
'edit-post' => 'default',
|
||||
'editor' => 'default',
|
||||
'format-library' => 'default',
|
||||
'keycodes' => 'default',
|
||||
'list-reusable-blocks' => 'default',
|
||||
'nux' => 'default',
|
||||
);
|
||||
|
||||
foreach ( $packages_dependencies as $package => $dependencies ) {
|
||||
$handle = 'wp-' . $package;
|
||||
$path = "/wp-includes/js/dist/$package$suffix.js";
|
||||
|
||||
$scripts->add( $handle, $path, $dependencies, false, 1 );
|
||||
|
||||
if ( isset( $package_translations[ $package ] ) ) {
|
||||
$scripts->set_translations( $handle, $package_translations[ $package ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -783,7 +783,8 @@ class Tests_Dependencies_Scripts extends WP_UnitTestCase {
|
||||
|
||||
$expected = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
|
||||
$expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
|
||||
'wp.i18n.setLocaleData( translations.locale_data, "default" );' .
|
||||
'translations.locale_data.messages[""].domain = "default";' .
|
||||
'wp.i18n.setLocaleData( translations.locale_data.messages, "default" );' .
|
||||
'})(' . file_get_contents( DIR_TESTDATA . '/languages/en_US-813e104eb47e13dd4cc5af844c618754.json' ) . ");\n</script>\n";
|
||||
$expected .= "<script type='text/javascript' src='/wp-includes/js/script.js'></script>\n";
|
||||
|
||||
@ -800,7 +801,8 @@ class Tests_Dependencies_Scripts extends WP_UnitTestCase {
|
||||
|
||||
$expected = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
|
||||
$expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
|
||||
'wp.i18n.setLocaleData( translations.locale_data, "internationalized-plugin" );' .
|
||||
'translations.locale_data.messages[""].domain = "internationalized-plugin";' .
|
||||
'wp.i18n.setLocaleData( translations.locale_data.messages, "internationalized-plugin" );' .
|
||||
'})(' . file_get_contents( DIR_TESTDATA . '/languages/plugins/internationalized-plugin-en_US-2f86cb96a0233e7cb3b6f03ad573be0b.json' ) . ");\n</script>\n";
|
||||
$expected .= "<script type='text/javascript' src='/wp-content/plugins/my-plugin/js/script.js'></script>\n";
|
||||
|
||||
@ -817,7 +819,8 @@ class Tests_Dependencies_Scripts extends WP_UnitTestCase {
|
||||
|
||||
$expected = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
|
||||
$expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
|
||||
'wp.i18n.setLocaleData( translations.locale_data, "internationalized-theme" );' .
|
||||
'translations.locale_data.messages[""].domain = "internationalized-theme";' .
|
||||
'wp.i18n.setLocaleData( translations.locale_data.messages, "internationalized-theme" );' .
|
||||
'})(' . file_get_contents( DIR_TESTDATA . '/languages/themes/internationalized-theme-en_US-2f86cb96a0233e7cb3b6f03ad573be0b.json' ) . ");\n</script>\n";
|
||||
$expected .= "<script type='text/javascript' src='/wp-content/themes/my-theme/js/script.js'></script>\n";
|
||||
|
||||
@ -834,7 +837,8 @@ class Tests_Dependencies_Scripts extends WP_UnitTestCase {
|
||||
|
||||
$expected = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
|
||||
$expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
|
||||
'wp.i18n.setLocaleData( translations.locale_data, "admin" );' .
|
||||
'translations.locale_data.messages[""].domain = "admin";' .
|
||||
'wp.i18n.setLocaleData( translations.locale_data.messages, "admin" );' .
|
||||
'})(' . file_get_contents( DIR_TESTDATA . '/languages/admin-en_US-script-handle.json' ) . ");\n</script>\n";
|
||||
$expected .= "<script type='text/javascript' src='/wp-admin/js/script.js'></script>\n";
|
||||
|
||||
@ -886,7 +890,8 @@ class Tests_Dependencies_Scripts extends WP_UnitTestCase {
|
||||
|
||||
$expected = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
|
||||
$expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
|
||||
'wp.i18n.setLocaleData( translations.locale_data, "default" );' .
|
||||
'translations.locale_data.messages[""].domain = "default";' .
|
||||
'wp.i18n.setLocaleData( translations.locale_data.messages, "default" );' .
|
||||
'})(' . file_get_contents( DIR_TESTDATA . '/languages/en_US-813e104eb47e13dd4cc5af844c618754.json' ) . ");\n</script>\n";
|
||||
$expected .= "<script type='text/javascript' src='/wp-includes/js/script.js'></script>\n";
|
||||
|
||||
@ -905,7 +910,8 @@ class Tests_Dependencies_Scripts extends WP_UnitTestCase {
|
||||
|
||||
$expected = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js'></script>";
|
||||
$expected .= "\n<script type='text/javascript'>\n(function( translations ){" .
|
||||
'wp.i18n.setLocaleData( translations.locale_data, "default" );' .
|
||||
'translations.locale_data.messages[""].domain = "default";' .
|
||||
'wp.i18n.setLocaleData( translations.locale_data.messages, "default" );' .
|
||||
'})(' . file_get_contents( DIR_TESTDATA . '/languages/en_US-813e104eb47e13dd4cc5af844c618754.json' ) . ");\n</script>\n";
|
||||
$expected .= "<script type='text/javascript' src='/wp-includes/js/script.js'></script>\n";
|
||||
$expected .= "<script type='text/javascript' src='/wp-includes/js/script2.js'></script>\n";
|
||||
|
Loading…
Reference in New Issue
Block a user