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.
Fixes #45161.

Built from https://develop.svn.wordpress.org/branches/5.0@43878


git-svn-id: http://core.svn.wordpress.org/branches/5.0@43707 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
herregroen 2018-11-08 11:34:48 +00:00
parent 3d6cb1b458
commit c22a63ec3a
4 changed files with 21 additions and 10 deletions

View File

@ -115,13 +115,6 @@ if ( 'auto-draft' === $post->post_status ) {
); );
} }
// Prepare Jed locale data.
$locale_data = wp_get_jed_locale_data( 'default' );
wp_add_inline_script(
'wp-i18n',
'wp.i18n.setLocaleData( ' . wp_json_encode( $locale_data ) . ' );'
);
// Preload server-registered block schemas. // Preload server-registered block schemas.
wp_add_inline_script( wp_add_inline_script(
'wp-blocks', 'wp-blocks',

View File

@ -532,7 +532,8 @@ class WP_Scripts extends WP_Dependencies {
} }
$output = '(function( translations ){' . $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 . ');'; '})(' . $json_translations . ');';
if ( $echo ) { if ( $echo ) {

View File

@ -320,7 +320,7 @@ function wp_default_packages_scripts( &$scripts ) {
'html-entities' => array( 'wp-polyfill' ), 'html-entities' => array( 'wp-polyfill' ),
'i18n' => array( 'wp-polyfill' ), 'i18n' => array( 'wp-polyfill' ),
'is-shallow-equal' => 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( 'list-reusable-blocks' => array(
'lodash', 'lodash',
'wp-api-fetch', 'wp-api-fetch',
@ -363,11 +363,28 @@ function wp_default_packages_scripts( &$scripts ) {
'wordcount' => array( 'wp-polyfill' ), '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 ) { foreach ( $packages_dependencies as $package => $dependencies ) {
$handle = 'wp-' . $package; $handle = 'wp-' . $package;
$path = "/wp-includes/js/dist/$package$suffix.js"; $path = "/wp-includes/js/dist/$package$suffix.js";
$scripts->add( $handle, $path, $dependencies, false, 1 ); $scripts->add( $handle, $path, $dependencies, false, 1 );
if ( isset( $package_translations[ $package ] ) ) {
$scripts->set_translations( $handle, $package_translations[ $package ] );
}
} }
} }

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.0-beta3-43877'; $wp_version = '5.0-beta3-43878';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.