Make WordPress Core

Changeset 37414


Ignore:
Timestamp:
05/10/2016 06:49:21 PM (8 years ago)
Author:
swissspidy
Message:

I18N: Reverse the order of loading plugin and theme translations.

load_theme_textdomain(), load_plugin_textdomain() and load_muplugin_textdomain() now try to load the .mo file from the wp-content/languages directory first. After the introduction of language packs, translation files are more likely to be located there.

Props swissspidy, sebastian.pisula.
Fixes #34213.

File:
1 edited

Legend:

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

    r37342 r37414  
    656656 *
    657657 * @since 1.5.0
     658 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first.
    658659 *
    659660 * @param string $domain          Unique identifier for retrieving translated strings
     
    664665 */
    665666function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) {
    666     $locale = get_locale();
    667667    /**
    668668     * Filter a plugin's locale.
     
    673673     * @param string $domain Text domain. Unique identifier for retrieving translated strings.
    674674     */
    675     $locale = apply_filters( 'plugin_locale', $locale, $domain );
    676 
    677     if ( false !== $plugin_rel_path ) {
     675    $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
     676
     677    $mofile = $domain . '-' . $locale . '.mo';
     678
     679    // Try to load from the languages directory first.
     680    if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) {
     681        return true;
     682    }
     683
     684    if ( false !== $plugin_rel_path ) {
    678685        $path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
    679686    } elseif ( false !== $deprecated ) {
     
    684691    }
    685692
    686     // Load the textdomain according to the plugin first
    687     $mofile = $domain . '-' . $locale . '.mo';
    688     if ( $loaded = load_textdomain( $domain, $path . '/'. $mofile ) )
    689         return $loaded;
    690 
    691     // Otherwise, load from the languages directory
    692     $mofile = WP_LANG_DIR . '/plugins/' . $mofile;
    693     return load_textdomain( $domain, $mofile );
     693    return load_textdomain( $domain, $path . '/' . $mofile );
    694694}
    695695
     
    698698 *
    699699 * @since 3.0.0
     700 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first.
    700701 *
    701702 * @param string $domain             Text domain. Unique identifier for retrieving translated strings.
     
    707708    /** This filter is documented in wp-includes/l10n.php */
    708709    $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
     710
     711    $mofile = $domain . '-' . $locale . '.mo';
     712
     713    // Try to load from the languages directory first.
     714    if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) {
     715        return true;
     716    }
     717
    709718    $path = trailingslashit( WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ) );
    710719
    711     // Load the textdomain according to the plugin first
    712     $mofile = $domain . '-' . $locale . '.mo';
    713     if ( $loaded = load_textdomain( $domain, $path . $mofile ) )
    714         return $loaded;
    715 
    716     // Otherwise, load from the languages directory
    717     $mofile = WP_LANG_DIR . '/plugins/' . $mofile;
    718     return load_textdomain( $domain, $mofile );
     720    return load_textdomain( $domain, $path . '/' . $mofile );
    719721}
    720722
     
    728730 *
    729731 * @since 1.5.0
     732 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first.
    730733 *
    731734 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
     
    735738 */
    736739function load_theme_textdomain( $domain, $path = false ) {
    737     $locale = get_locale();
    738740    /**
    739741     * Filter a theme's locale.
     
    744746     * @param string $domain Text domain. Unique identifier for retrieving translated strings.
    745747     */
    746     $locale = apply_filters( 'theme_locale', $locale, $domain );
    747 
    748     if ( ! $path )
     748    $locale = apply_filters( 'theme_locale', get_locale(), $domain );
     749
     750    $mofile = $domain . '-' . $locale . '.mo';
     751
     752    // Try to load from the languages directory first.
     753    if ( load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile ) ) {
     754        return true;
     755    }
     756
     757    if ( ! $path ) {
    749758        $path = get_template_directory();
    750 
    751     // Load the textdomain according to the theme
    752     $mofile = untrailingslashit( $path ) . "/{$locale}.mo";
    753     if ( $loaded = load_textdomain( $domain, $mofile ) )
    754         return $loaded;
    755 
    756     // Otherwise, load from the languages directory
    757     $mofile = WP_LANG_DIR . "/themes/{$domain}-{$locale}.mo";
    758     return load_textdomain( $domain, $mofile );
     759    }
     760
     761    return load_textdomain( $domain, $path . '/' . $locale . '.mo' );
    759762}
    760763
Note: See TracChangeset for help on using the changeset viewer.