WordPress.org

Make WordPress Core

Ticket #34213: 34213.2.diff

File 34213.2.diff, 5.4 KB (added by swissspidy, 3 years ago)
  • src/wp-includes/l10n.php

    diff --git src/wp-includes/l10n.php src/wp-includes/l10n.php
    index 6a88fbb..878619a 100644
    function load_default_textdomain( $locale = null ) { 
    655655 * The .mo file should be named based on the text domain with a dash, and then the locale exactly.
    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
    660661 * @param string $deprecated      Use the $plugin_rel_path parameter instead.
    function load_default_textdomain( $locale = null ) { 
    663664 * @return bool True when textdomain is successfully loaded, false otherwise.
    664665 */
    665666function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) {
    666         $locale = get_locale();
    667667        /**
    668668         * Filter a plugin's locale.
    669669         *
    function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path 
    672672         * @param string $locale The plugin's current locale.
    673673         * @param string $domain Text domain. Unique identifier for retrieving translated strings.
    674674         */
    675         $locale = apply_filters( 'plugin_locale', $locale, $domain );
     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        }
    676683
    677         if ( false !== $plugin_rel_path ) {
     684        if ( false !== $plugin_rel_path ) {
    678685                $path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
    679686        } elseif ( false !== $deprecated ) {
    680687                _deprecated_argument( __FUNCTION__, '2.7' );
    function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path 
    683690                $path = WP_PLUGIN_DIR;
    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
    696696/**
    697697 * Load the translated strings for a plugin residing in the mu-plugins directory.
    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.
    702703 * @param string $mu_plugin_rel_path Relative to WPMU_PLUGIN_DIR directory in which the .mo file resides.
    function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path 
    706707function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
    707708        /** This filter is documented in wp-includes/l10n.php */
    708709        $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
    709         $path = trailingslashit( WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ) );
    710710
    711         // Load the textdomain according to the plugin first
    712711        $mofile = $domain . '-' . $locale . '.mo';
    713         if ( $loaded = load_textdomain( $domain, $path . $mofile ) )
    714                 return $loaded;
    715712
    716         // Otherwise, load from the languages directory
    717         $mofile = WP_LANG_DIR . '/plugins/' . $mofile;
    718         return load_textdomain( $domain, $mofile );
     713        // Try to load from the languages directory first.
     714        if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) {
     715                return true;
     716        }
     717
     718        $path = trailingslashit( WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ) );
     719
     720        return load_textdomain( $domain, $path . '/' . $mofile );
    719721}
    720722
    721723/**
    function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { 
    727729 * The .mo files must be named based on the locale exactly.
    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.
    732735 * @param string $path   Optional. Path to the directory containing the .mo file.
    function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { 
    734737 * @return bool True when textdomain is successfully loaded, false otherwise.
    735738 */
    736739function load_theme_textdomain( $domain, $path = false ) {
    737         $locale = get_locale();
    738740        /**
    739741         * Filter a theme's locale.
    740742         *
    function load_theme_textdomain( $domain, $path = false ) { 
    743745         * @param string $locale The theme's current locale.
    744746         * @param string $domain Text domain. Unique identifier for retrieving translated strings.
    745747         */
    746         $locale = apply_filters( 'theme_locale', $locale, $domain );
     748        $locale = apply_filters( 'theme_locale', get_locale(), $domain );
    747749
    748         if ( ! $path )
    749                 $path = get_template_directory();
     750        $mofile = $domain . '-' . $locale . '.mo';
    750751
    751         // Load the textdomain according to the theme
    752         $mofile = untrailingslashit( $path ) . "/{$locale}.mo";
    753         if ( $loaded = load_textdomain( $domain, $mofile ) )
    754                 return $loaded;
     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 ) {
     758                $path = get_template_directory();
     759        }
    755760
    756         // Otherwise, load from the languages directory
    757         $mofile = WP_LANG_DIR . "/themes/{$domain}-{$locale}.mo";
    758         return load_textdomain( $domain, $mofile );
     761        return load_textdomain( $domain, $path . '/' . $locale . '.mo' );
    759762}
    760763
    761764/**