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.

git-svn-id: https://develop.svn.wordpress.org/trunk@44403 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90)
2019-01-06 16:22:46 +00:00
parent 899e5163fa
commit 690b0cbf83
2 changed files with 105 additions and 40 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 );