Make WordPress Core


Ignore:
Timestamp:
05/10/2016 08:30:19 PM (8 years ago)
Author:
swissspidy
Message:

I18N: Add changes missed in [37415].

See #34114.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/l10n.php

    r37414 r37416  
    784784
    785785/**
     786 * Just in time loading of plugin and theme textdomains.
     787 *
     788 * When a textdomain is encountered for the first time, we try to load the translation file
     789 * from wp-content/languages, removing the need to call `load_plugin_texdomain()` or
     790 * `load_theme_texdomain()`. Holds a cached list of available .mo files to improve performance.
     791 *
     792 * @since 4.6.0
     793 * @access private
     794 *
     795 * @see get_translations_for_domain()
     796 *
     797 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
     798 * @return bool True when the textdomain is successfully loaded, false otherwise.
     799 */
     800function _load_textdomain_just_in_time( $domain ) {
     801    static $cached_mofiles = null;
     802
     803    // Short-circuit if domain is 'default' which is reserved for core.
     804    if ( 'default' === $domain ) {
     805        return false;
     806    }
     807
     808    if ( null === $cached_mofiles ) {
     809        $cached_mofiles = array();
     810
     811        $locations = array(
     812            WP_LANG_DIR . '/plugins',
     813            WP_LANG_DIR . '/themes',
     814        );
     815
     816        foreach ( $locations as $location ) {
     817            foreach ( get_available_languages( $location ) as $file ) {
     818                $cached_mofiles[] = "{$location}/{$file}.mo";
     819            }
     820        }
     821    }
     822
     823    $locale = get_locale();
     824    $mofile = "{$domain}-{$locale}.mo";
     825
     826    if ( in_array( WP_LANG_DIR . '/plugins/' . $mofile, $cached_mofiles ) ) {
     827        return load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile );
     828    }
     829
     830    if ( in_array( WP_LANG_DIR . '/themes/' . $mofile, $cached_mofiles ) ) {
     831        return load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile );
     832    }
     833
     834    return false;
     835}
     836
     837/**
    786838 * Return the Translations instance for a text domain.
    787839 *
     
    797849function get_translations_for_domain( $domain ) {
    798850    global $l10n;
    799     if ( isset( $l10n[ $domain ] ) ) {
     851    if ( isset( $l10n[ $domain ] ) || _load_textdomain_just_in_time( $domain ) ) {
    800852        return $l10n[ $domain ];
    801853    }
Note: See TracChangeset for help on using the changeset viewer.