mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-03-31 10:44:26 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@37855 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -22,6 +22,8 @@ class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase {
|
||||
add_filter( 'template_root', array( $this, 'filter_theme_root' ) );
|
||||
wp_clean_themes_cache();
|
||||
unset( $GLOBALS['wp_themes'] );
|
||||
|
||||
unset( $GLOBALS['l10n_unloaded'] );
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
@@ -89,7 +91,7 @@ class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 341142
|
||||
* @ticket 34114
|
||||
*/
|
||||
public function test_get_translations_for_domain_does_not_return_null_if_override_load_textdomain_is_used() {
|
||||
add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
|
||||
@@ -100,4 +102,43 @@ class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase {
|
||||
|
||||
$this->assertTrue( $translations instanceof NOOP_Translations );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37113
|
||||
*/
|
||||
public function test_should_allow_unloading_of_text_domain() {
|
||||
add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
|
||||
|
||||
require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php';
|
||||
|
||||
$expected_output_before = i18n_plugin_test();
|
||||
$is_textdomain_loaded_before = is_textdomain_loaded( 'internationalized-plugin' );
|
||||
|
||||
unload_textdomain( 'internationalized-plugin' );
|
||||
remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
|
||||
|
||||
$expected_output_after = i18n_plugin_test();
|
||||
$is_textdomain_loaded_after = is_textdomain_loaded( 'internationalized-plugin' );
|
||||
|
||||
add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
|
||||
load_textdomain( 'internationalized-plugin', WP_LANG_DIR . '/plugins/internationalized-plugin-de_DE.mo' );
|
||||
|
||||
$expected_output_final = i18n_plugin_test();
|
||||
$is_textdomain_loaded_final = is_textdomain_loaded( 'internationalized-plugin' );
|
||||
|
||||
unload_textdomain( 'internationalized-plugin' );
|
||||
remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
|
||||
|
||||
// Text domain loaded just in time.
|
||||
$this->assertSame( 'Das ist ein Dummy Plugin', $expected_output_before );
|
||||
$this->assertTrue( $is_textdomain_loaded_before );
|
||||
|
||||
// Text domain unloaded.
|
||||
$this->assertSame( 'This is a dummy plugin', $expected_output_after );
|
||||
$this->assertFalse( $is_textdomain_loaded_after );
|
||||
|
||||
// Text domain loaded manually again.
|
||||
$this->assertSame( 'Das ist ein Dummy Plugin', $expected_output_final );
|
||||
$this->assertTrue( $is_textdomain_loaded_final );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user