Make WordPress Core


Ignore:
Timestamp:
05/29/2023 08:34:43 AM (22 months ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/l10n/wpLocaleSwitcher.php

    r55224 r55865  
    385385        $locale_switched_site_locale  = switch_to_locale( $site_locale ); // True.
    386386        $site_locale_after_switch     = get_locale();
    387         $language_header_after_switch = isset( $l10n['default'] ); // en_US
     387        $language_header_after_switch = is_textdomain_loaded( 'default' ); // en_US
    388388
    389389        restore_current_locale();
Note: See TracChangeset for help on using the changeset viewer.