mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
I18N, Script Loader: Don't register empty locale data objects.
For `wp.i18n` the library [https://github.com/messageformat/Jed Jed] was initially used which was throwing an error if a domain was not registered but used in a translate function. Later, the library was replaced by [https://github.com/aduth/tannin Tannin] which no longer requires the domain to be registered and thus we can avoid printing an empty-ish translations script that doesn't add any translations. Props jsnajdr. Fixes #55250. git-svn-id: https://develop.svn.wordpress.org/trunk@52937 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
10875b1e42
commit
8a64e9fef9
@ -599,8 +599,7 @@ class WP_Scripts extends WP_Dependencies {
|
||||
$json_translations = load_script_textdomain( $handle, $domain, $path );
|
||||
|
||||
if ( ! $json_translations ) {
|
||||
// Register empty locale data object to ensure the domain still exists.
|
||||
$json_translations = '{ "locale_data": { "messages": { "": {} } } }';
|
||||
return false;
|
||||
}
|
||||
|
||||
$output = <<<JS
|
||||
|
||||
@ -740,13 +740,6 @@ JS;
|
||||
$expected .= "<script type='text/javascript' id='wp-i18n-js-after'>\n";
|
||||
$expected .= "wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } );\n";
|
||||
$expected .= "</script>\n";
|
||||
$expected .= "<script type='text/javascript' id='wp-a11y-js-translations'>\n";
|
||||
$expected .= "( function( domain, translations ) {\n";
|
||||
$expected .= " var localeData = translations.locale_data[ domain ] || translations.locale_data.messages;\n";
|
||||
$expected .= " localeData[\"\"].domain = domain;\n";
|
||||
$expected .= " wp.i18n.setLocaleData( localeData, domain );\n";
|
||||
$expected .= "} )( \"default\", { \"locale_data\": { \"messages\": { \"\": {} } } } );\n";
|
||||
$expected .= "</script>\n";
|
||||
$expected .= "<script type='text/javascript' src='/wp-includes/js/dist/a11y{$suffix}.js' id='wp-a11y-js'></script>\n";
|
||||
$expected .= "<script type='text/javascript' src='http://example2.com' id='test-example2-js'></script>\n";
|
||||
$expected .= "<script type='text/javascript' id='test-example2-js-after'>\nconsole.log(\"after\");\n</script>\n";
|
||||
@ -994,6 +987,7 @@ JS;
|
||||
|
||||
/**
|
||||
* @ticket 45103
|
||||
* @ticket 55250
|
||||
*/
|
||||
public function test_wp_set_script_translations_when_translation_file_does_not_exist() {
|
||||
wp_register_script( 'wp-i18n', '/wp-includes/js/dist/wp-i18n.js', array(), null );
|
||||
@ -1001,19 +995,6 @@ JS;
|
||||
wp_set_script_translations( 'test-example', 'admin', DIR_TESTDATA . '/languages/' );
|
||||
|
||||
$expected = "<script type='text/javascript' src='/wp-includes/js/dist/wp-i18n.js' id='wp-i18n-js'></script>\n";
|
||||
$expected .= str_replace(
|
||||
array(
|
||||
'__DOMAIN__',
|
||||
'__HANDLE__',
|
||||
'__JSON_TRANSLATIONS__',
|
||||
),
|
||||
array(
|
||||
'admin',
|
||||
'test-example',
|
||||
'{ "locale_data": { "messages": { "": {} } } }',
|
||||
),
|
||||
$this->wp_scripts_print_translations_output
|
||||
);
|
||||
$expected .= "<script type='text/javascript' src='/wp-admin/js/script.js' id='test-example-js'></script>\n";
|
||||
|
||||
$this->assertSameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
|
||||
|
||||
Loading…
Reference in New Issue
Block a user