mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-03-31 18:54:29 +00:00
I18N: Improve _load_textdomain_just_in_time() logic when there are no translation files.
Fixes a performance issue where the JIT logic is invoked for every translation call if the there are no translations in the current locale. With this change, the information is cached by adding `Noop_Translations` instances to the global `$l10n` array. This way, `get_translations_for_domain()` returns earlier, thus avoiding subsequent `_load_textdomain_just_in_time()` calls. Props swissspidy, johnbillion, ocean90. Fixes #58321. git-svn-id: https://develop.svn.wordpress.org/trunk@55865 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -121,6 +121,27 @@ class Tests_L10n_LoadTextdomainJustInTime extends WP_UnitTestCase {
|
||||
$this->assertInstanceOf( 'NOOP_Translations', $translations );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 58321
|
||||
*
|
||||
* @covers ::get_translations_for_domain
|
||||
*/
|
||||
public function test_get_translations_for_domain_get_locale_is_called_only_once() {
|
||||
$filter_locale = new MockAction();
|
||||
add_filter( 'locale', array( $filter_locale, 'filter' ) );
|
||||
|
||||
get_translations_for_domain( 'internationalized-plugin' );
|
||||
get_translations_for_domain( 'internationalized-plugin' );
|
||||
get_translations_for_domain( 'internationalized-plugin' );
|
||||
$translations = get_translations_for_domain( 'internationalized-plugin' );
|
||||
|
||||
remove_filter( 'locale', array( $filter_locale, 'filter' ) );
|
||||
|
||||
$this->assertSame( 1, $filter_locale->get_call_count() );
|
||||
$this->assertInstanceOf( 'NOOP_Translations', $translations );
|
||||
$this->assertFalse( is_textdomain_loaded( 'internationalized-plugin' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37113
|
||||
*
|
||||
|
||||
@@ -384,7 +384,7 @@ class Tests_L10n_wpLocaleSwitcher extends WP_UnitTestCase {
|
||||
$locale_switched_user_locale = switch_to_locale( $user_locale ); // False.
|
||||
$locale_switched_site_locale = switch_to_locale( $site_locale ); // True.
|
||||
$site_locale_after_switch = get_locale();
|
||||
$language_header_after_switch = isset( $l10n['default'] ); // en_US
|
||||
$language_header_after_switch = is_textdomain_loaded( 'default' ); // en_US
|
||||
|
||||
restore_current_locale();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user