mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 21:00:21 +00:00
I18N: Use the user's locale when loading text domains in the admin.
Leverages `get_user_locale()` in `load_*_textdomain()` and `_load_textdomain_just_in_time()` to always load translations in the user's language when in the admin. This re-introduces [39069], but now with additional tests and a `function_exists( 'wp_get_current_user' )` check in `get_user_locale()` in case it gets used early. Props swissspidy, ocean90. Fixes #38485. git-svn-id: https://develop.svn.wordpress.org/trunk@39127 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -6,6 +6,14 @@
|
||||
*/
|
||||
class Tests_L10n_loadTextdomain extends WP_UnitTestCase {
|
||||
protected $locale;
|
||||
protected static $user_id;
|
||||
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$user_id = $factory->user->create( array(
|
||||
'role' => 'administrator',
|
||||
'locale' => 'de_DE',
|
||||
) );
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
@@ -183,15 +191,57 @@ class Tests_L10n_loadTextdomain extends WP_UnitTestCase {
|
||||
$this->assertSame( get_locale(), $this->locale );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38485
|
||||
*/
|
||||
public function test_load_muplugin_textdomain_user_locale() {
|
||||
set_current_screen( 'dashboard' );
|
||||
wp_set_current_user( self::$user_id );
|
||||
|
||||
load_muplugin_textdomain( 'wp-tests-domain' );
|
||||
|
||||
set_current_screen( 'front' );
|
||||
|
||||
$this->assertSame( get_user_locale(), $this->locale );
|
||||
}
|
||||
|
||||
public function test_load_plugin_textdomain_site_locale() {
|
||||
load_plugin_textdomain( 'wp-tests-domain' );
|
||||
|
||||
$this->assertSame( get_locale(), $this->locale );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38485
|
||||
*/
|
||||
public function test_load_plugin_textdomain_user_locale() {
|
||||
set_current_screen( 'dashboard' );
|
||||
wp_set_current_user( self::$user_id );
|
||||
|
||||
load_plugin_textdomain( 'wp-tests-domain' );
|
||||
|
||||
set_current_screen( 'front' );
|
||||
|
||||
$this->assertSame( get_user_locale(), $this->locale );
|
||||
}
|
||||
|
||||
public function test_load_theme_textdomain_site_locale() {
|
||||
load_theme_textdomain( 'wp-tests-domain' );
|
||||
|
||||
$this->assertSame( get_locale(), $this->locale );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38485
|
||||
*/
|
||||
public function test_load_theme_textdomain_user_locale() {
|
||||
set_current_screen( 'dashboard' );
|
||||
wp_set_current_user( self::$user_id );
|
||||
|
||||
load_theme_textdomain( 'wp-tests-domain' );
|
||||
|
||||
set_current_screen( 'front' );
|
||||
|
||||
$this->assertSame( get_user_locale(), $this->locale );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,16 @@
|
||||
* @group i18n
|
||||
*/
|
||||
class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase {
|
||||
protected $orig_theme_dir;
|
||||
protected $theme_root;
|
||||
protected static $user_id;
|
||||
|
||||
private $orig_theme_dir;
|
||||
private $theme_root;
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$user_id = $factory->user->create( array(
|
||||
'role' => 'administrator',
|
||||
'locale' => 'de_DE',
|
||||
) );
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
@@ -171,4 +178,38 @@ class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase {
|
||||
|
||||
$this->assertSame( 'Das ist ein Dummy Theme', $expected );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38485
|
||||
*/
|
||||
public function test_plugin_translation_with_user_locale() {
|
||||
require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php';
|
||||
|
||||
set_current_screen( 'dashboard' );
|
||||
wp_set_current_user( self::$user_id );
|
||||
|
||||
$expected = i18n_plugin_test();
|
||||
|
||||
set_current_screen( 'front' );
|
||||
|
||||
$this->assertSame( 'Das ist ein Dummy Plugin', $expected );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38485
|
||||
*/
|
||||
public function test_theme_translation_with_user_locale() {
|
||||
switch_theme( 'internationalized-theme' );
|
||||
set_current_screen( 'dashboard' );
|
||||
wp_set_current_user( self::$user_id );
|
||||
|
||||
require_once get_stylesheet_directory() . '/functions.php';
|
||||
|
||||
$expected = i18n_theme_test();
|
||||
|
||||
set_current_screen( 'front' );
|
||||
switch_theme( WP_DEFAULT_THEME );
|
||||
|
||||
$this->assertSame( 'Das ist ein Dummy Theme', $expected );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user