I18N/Script Loader: Support text domains other than "messages".

The inline JavaScript added by `WP_Scripts::print_translations()` should check whether `locale_data.$text_domain` exists and fall back to `locale_data.messages` otherwise.

Props swissspidy.
See #45441.
Built from https://develop.svn.wordpress.org/trunk@44403


git-svn-id: http://core.svn.wordpress.org/trunk@44233 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2019-01-06 16:23:49 +00:00
parent 1c4a23faad
commit 49351e0578
2 changed files with 8 additions and 5 deletions

View File

@ -546,10 +546,13 @@ class WP_Scripts extends WP_Dependencies {
$json_translations = '{ "locale_data": { "messages": { "": {} } } }';
}
$output = '(function( translations ){' .
'translations.locale_data.messages[""].domain = "' . $domain . '";' .
'wp.i18n.setLocaleData( translations.locale_data.messages, "' . $domain . '" );' .
'})(' . $json_translations . ');';
$output = <<<JS
( function( domain, translations ) {
var localeData = translations.locale_data[ domain ] || translations.locale_data.messages;
localeData[""].domain = domain;
wp.i18n.setLocaleData( localeData, domain );
} )( "{$domain}", {$json_translations} );
JS;
if ( $echo ) {
printf( "<script type='text/javascript'>\n%s\n</script>\n", $output );

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.1-alpha-44402';
$wp_version = '5.1-alpha-44403';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.