WordPress.org

Make WordPress Core

Ticket #37113: 37113.diff

File 37113.diff, 3.0 KB (added by swissspidy, 5 years ago)
  • src/wp-includes/l10n.php

    diff --git src/wp-includes/l10n.php src/wp-includes/l10n.php
    index fa63b19..115f0f4 100644
    function load_textdomain( $domain, $mofile ) { 
    571571 *
    572572 * @since 3.0.0
    573573 *
    574  * @global array $l10n
     574 * @global array $l10n          An array of all currently loaded text domains.
     575 * @global array $l10n_unloaded An array of all text domains that have been unloaded again.
    575576 *
    576577 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
    577578 * @return bool Whether textdomain was unloaded.
    578579 */
    579580function unload_textdomain( $domain ) {
    580         global $l10n;
     581        global $l10n, $l10n_unloaded;
    581582
    582583        /**
    583584         * Filters whether to override the text domain unloading.
    function unload_textdomain( $domain ) { 
    603604
    604605        if ( isset( $l10n[$domain] ) ) {
    605606                unset( $l10n[$domain] );
     607
     608                $l10n_unloaded = (array) $l10n_unloaded;
     609                $l10n_unloaded[] = $domain;
     610
    606611                return true;
    607612        }
    608613
    function load_child_theme_textdomain( $domain, $path = false ) { 
    793798 * @access private
    794799 *
    795800 * @see get_translations_for_domain()
     801 * @global array $l10n_unloaded An array of all text domains that have been unloaded again.
    796802 *
    797803 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
    798804 * @return bool True when the textdomain is successfully loaded, false otherwise.
    799805 */
    800806function _load_textdomain_just_in_time( $domain ) {
     807        global $l10n_unloaded;
     808
    801809        static $cached_mofiles = null;
    802810
    803811        // Short-circuit if domain is 'default' which is reserved for core.
    804         if ( 'default' === $domain ) {
     812        if ( 'default' === $domain || in_array( $domain, (array) $l10n_unloaded ) ) {
    805813                return false;
    806814        }
    807815
  • tests/phpunit/tests/l10n/loadTextdomainJustInTime.php

    diff --git tests/phpunit/tests/l10n/loadTextdomainJustInTime.php tests/phpunit/tests/l10n/loadTextdomainJustInTime.php
    index 14a2b0d..5eabfac 100644
    class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase { 
    100100
    101101                $this->assertTrue( $translations instanceof NOOP_Translations );
    102102        }
     103
     104        /**
     105         * @ticket 37113
     106         */
     107        public function test_should_allow_unloading_of_text_domain() {
     108                add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
     109
     110                require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php';
     111
     112                load_textdomain( 'internationalized-plugin', WP_LANG_DIR . '/plugins/internationalized-plugin-de_DE.mo' );
     113
     114                $expected_output      = i18n_plugin_test();
     115                $is_textdomain_loaded = is_textdomain_loaded( 'internationalized-plugin' );
     116
     117                unload_textdomain( 'internationalized-plugin' );
     118                remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
     119
     120                $this->assertSame( 'Das ist ein Dummy Plugin', $expected_output );
     121                $this->assertTrue( $is_textdomain_loaded );
     122
     123                $this->assertFalse( is_textdomain_loaded( 'internationalized-plugin' ) );
     124                $this->assertSame( 'This is a dummy plugin', i18n_plugin_test() );
     125        }
    103126}