Make WordPress Core

Ticket #39210: 39210.3.diff

File 39210.3.diff, 3.3 KB (added by dd32, 6 years ago)
  • wp-includes/class-wp-locale-switcher.php

    class WP_Locale_Switcher { 
    188188         *
    189189         * @param string $locale The locale to load translations for.
    190190         */
    191191        private function load_translations( $locale ) {
    192192                global $l10n;
    193193
    194194                $domains = $l10n ? array_keys( $l10n ) : array();
    195195
    196196                load_default_textdomain( $locale );
    197197
    198198                foreach ( $domains as $domain ) {
    199199                        if ( 'default' === $domain ) {
    200200                                continue;
    201201                        }
    202202
    203                         unload_textdomain( $domain );
     203                        unload_textdomain( $domain, true );
    204204                        get_translations_for_domain( $domain );
    205205                }
    206206        }
    207207
    208208        /**
    209209         * Changes the site's locale to the given one.
    210210         *
    211211         * Loads the translations, changes the global `$wp_locale` object and updates
    212212         * all post type labels.
    213213         *
    214214         * @since 4.7.0
    215215         *
    216216         * @global WP_Locale $wp_locale The WordPress date and time locale object.
    217217         *
    218218         * @param string $locale The locale to change to.
  • wp-includes/l10n.php

    function load_textdomain( $domain, $mofi 
    662662        unset( $l10n_unloaded[ $domain ] );
    663663
    664664        $l10n[ $domain ] = &$mo;
    665665
    666666        return true;
    667667}
    668668
    669669/**
    670670 * Unload translations for a text domain.
    671671 *
    672672 * @since 3.0.0
    673673 *
    674674 * @global MO[] $l10n          An array of all currently loaded text domains.
    675675 * @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again.
    676676 *
    677  * @param string $domain Text domain. Unique identifier for retrieving translated strings.
     677 * @param string $domain     Text domain. Unique identifier for retrieving translated strings.
     678 * @param bool   $reloadable Whether this textdomain should be loaded JIT again.
    678679 * @return bool Whether textdomain was unloaded.
    679680 */
    680 function unload_textdomain( $domain ) {
     681function unload_textdomain( $domain, $reloadable = false ) {
    681682        global $l10n, $l10n_unloaded;
    682683
    683684        $l10n_unloaded = (array) $l10n_unloaded;
    684685
    685686        /**
    686687         * Filters whether to override the text domain unloading.
    687688         *
    688689         * @since 3.0.0
    689690         *
    690691         * @param bool   $override Whether to override the text domain unloading. Default false.
    691692         * @param string $domain   Text domain. Unique identifier for retrieving translated strings.
    692693         */
    693694        $plugin_override = apply_filters( 'override_unload_textdomain', false, $domain );
    694695
    695696        if ( $plugin_override ) {
    696                 $l10n_unloaded[ $domain ] = true;
     697                if ( ! $reloadable ) {
     698                        $l10n_unloaded[ $domain ] = true;
     699                }
    697700
    698701                return true;
    699702        }
    700703
    701704        /**
    702705         * Fires before the text domain is unloaded.
    703706         *
    704707         * @since 3.0.0
    705708         *
    706709         * @param string $domain Text domain. Unique identifier for retrieving translated strings.
    707710         */
    708711        do_action( 'unload_textdomain', $domain );
    709712
    710713        if ( isset( $l10n[ $domain ] ) ) {
    711714                unset( $l10n[ $domain ] );
    712715
    713                 $l10n_unloaded[ $domain ] = true;
     716                if ( ! $reloadable ) {
     717                        $l10n_unloaded[ $domain ] = true;
     718                }
    714719
    715720                return true;
    716721        }
    717722
    718723        return false;
    719724}
    720725
    721726/**
    722727 * Load default translated strings based on locale.
    723728 *
    724729 * Loads the .mo file in WP_LANG_DIR constant path from WordPress root.
    725730 * The translated (.mo) file is named based on the locale.
    726731 *
    727732 * @see load_textdomain()
    728733 *