From 8a64e9fef9c9eae3a36862bd4de1d7b430d89498 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Tue, 15 Mar 2022 15:57:57 +0000 Subject: [PATCH] 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 --- src/wp-includes/class.wp-scripts.php | 3 +-- tests/phpunit/tests/dependencies/scripts.php | 21 +------------------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/src/wp-includes/class.wp-scripts.php b/src/wp-includes/class.wp-scripts.php index 10104d6dfa..8edf4ee49b 100644 --- a/src/wp-includes/class.wp-scripts.php +++ b/src/wp-includes/class.wp-scripts.php @@ -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 = <<\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 = "\n"; - $expected .= str_replace( - array( - '__DOMAIN__', - '__HANDLE__', - '__JSON_TRANSLATIONS__', - ), - array( - 'admin', - 'test-example', - '{ "locale_data": { "messages": { "": {} } } }', - ), - $this->wp_scripts_print_translations_output - ); $expected .= "\n"; $this->assertSameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );