WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/21/2016 04:06:38 PM (3 years ago)
Author:
ocean90
Message:

I18N: Add an additional caching layer for _load_textdomain_just_in_time().

Previously, if no translation files exist for a text domain, _load_textdomain_just_in_time() went through the entire process each time it was called. This results in an increased call to get_locale() and its locale filter.
This change splits the logic into _get_path_to_translation() and _get_path_to_translation_from_lang_dir(). The former, which is used by _load_textdomain_just_in_time(), caches the result of the latter. It also removes some non-working code from WP_Locale_Switcher::load_translations().

Props jrf, swissspidy, sharkomatic, ocean90.
Fixes #37997.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-locale-switcher.php

    r38961 r39330  
    203203            }
    204204
    205             $mofile = $l10n[ $domain ]->get_filename();
    206 
    207205            unload_textdomain( $domain );
    208 
    209             if ( $mofile ) {
    210                 load_textdomain( $domain, $mofile );
    211             }
    212 
    213206            get_translations_for_domain( $domain );
    214207        }
     
    229222     */
    230223    private function change_locale( $locale ) {
     224        // Reset translation availability information.
     225        _get_path_to_translation( null, true );
     226
    231227        $this->load_translations( $locale );
    232228
Note: See TracChangeset for help on using the changeset viewer.