WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/23/2016 02:47:44 PM (5 years ago)
Author:
swissspidy
Message:

I18N: Enable unloading of text domains that have been loaded just in time.

[37415] removed the requirement to call load_plugin_textdomain() / load_theme_textdomain(). This caused unload_textdomain() to not work properly anymore in these cases.

With this change, unloaded text domains need to be explicitly loaded manually if you want to use them again.

Props swissspidy, ocean90.
Fixes #37113. See #34114.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php

    r37440 r37855  
    2323        wp_clean_themes_cache();
    2424        unset( $GLOBALS['wp_themes'] );
     25
     26        unset( $GLOBALS['l10n_unloaded'] );
    2527    }
    2628
     
    9092
    9193    /**
    92      * @ticket 341142
     94     * @ticket 34114
    9395     */
    9496    public function test_get_translations_for_domain_does_not_return_null_if_override_load_textdomain_is_used() {
     
    101103        $this->assertTrue( $translations instanceof NOOP_Translations );
    102104    }
     105
     106    /**
     107     * @ticket 37113
     108     */
     109    public function test_should_allow_unloading_of_text_domain() {
     110        add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
     111
     112        require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php';
     113
     114        $expected_output_before      = i18n_plugin_test();
     115        $is_textdomain_loaded_before = is_textdomain_loaded( 'internationalized-plugin' );
     116
     117        unload_textdomain( 'internationalized-plugin' );
     118        remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
     119
     120        $expected_output_after      = i18n_plugin_test();
     121        $is_textdomain_loaded_after = is_textdomain_loaded( 'internationalized-plugin' );
     122
     123        add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
     124        load_textdomain( 'internationalized-plugin', WP_LANG_DIR . '/plugins/internationalized-plugin-de_DE.mo' );
     125
     126        $expected_output_final      = i18n_plugin_test();
     127        $is_textdomain_loaded_final = is_textdomain_loaded( 'internationalized-plugin' );
     128
     129        unload_textdomain( 'internationalized-plugin' );
     130        remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
     131
     132        // Text domain loaded just in time.
     133        $this->assertSame( 'Das ist ein Dummy Plugin', $expected_output_before );
     134        $this->assertTrue( $is_textdomain_loaded_before );
     135
     136        // Text domain unloaded.
     137        $this->assertSame( 'This is a dummy plugin', $expected_output_after );
     138        $this->assertFalse( $is_textdomain_loaded_after );
     139
     140        // Text domain loaded manually again.
     141        $this->assertSame( 'Das ist ein Dummy Plugin', $expected_output_final );
     142        $this->assertTrue( $is_textdomain_loaded_final );
     143    }
    103144}
Note: See TracChangeset for help on using the changeset viewer.