I18N: In get_translations_for_domain()
check if the global $l10n
was set by _load_textdomain_just_in_time()
before accessing it.
Props danielhuesken. Fixes #34114. git-svn-id: https://develop.svn.wordpress.org/trunk@37440 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
a595b2ff53
commit
999af2444c
@ -848,7 +848,7 @@ function _load_textdomain_just_in_time( $domain ) {
|
||||
*/
|
||||
function get_translations_for_domain( $domain ) {
|
||||
global $l10n;
|
||||
if ( isset( $l10n[ $domain ] ) || _load_textdomain_just_in_time( $domain ) ) {
|
||||
if ( isset( $l10n[ $domain ] ) || ( _load_textdomain_just_in_time( $domain ) && isset( $l10n[ $domain ] ) ) ) {
|
||||
return $l10n[ $domain ];
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,7 @@ class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase {
|
||||
$expected_output = i18n_plugin_test();
|
||||
$is_textdomain_loaded_after = is_textdomain_loaded( 'internationalized-plugin' );
|
||||
|
||||
unload_textdomain( 'internationalized-plugin' );
|
||||
remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
|
||||
|
||||
$this->assertFalse( $is_textdomain_loaded_before );
|
||||
@ -79,10 +80,24 @@ class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase {
|
||||
$expected_output = i18n_theme_test();
|
||||
$is_textdomain_loaded_after = is_textdomain_loaded( 'internationalized-theme' );
|
||||
|
||||
unload_textdomain( 'internationalized-theme' );
|
||||
remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
|
||||
|
||||
$this->assertFalse( $is_textdomain_loaded_before );
|
||||
$this->assertSame( 'Das ist ein Dummy Theme', $expected_output );
|
||||
$this->assertTrue( $is_textdomain_loaded_after );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 341142
|
||||
*/
|
||||
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' ) );
|
||||
add_filter( 'override_load_textdomain', '__return_true' );
|
||||
$translations = get_translations_for_domain( 'internationalized-plugin' );
|
||||
remove_filter( 'override_load_textdomain', '__return_true' );
|
||||
remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
|
||||
|
||||
$this->assertTrue( $translations instanceof NOOP_Translations );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user