Make WordPress Core


Ignore:
Timestamp:
11/03/2016 08:07:08 PM (10 years ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

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

    r39125 r39127  
    77class Tests_L10n_loadTextdomain extends WP_UnitTestCase {
    88        protected $locale;
     9        protected static $user_id;
     10
     11        public static function wpSetUpBeforeClass( $factory ) {
     12                self::$user_id = $factory->user->create( array(
     13                        'role'   => 'administrator',
     14                        'locale' => 'de_DE',
     15                ) );
     16        }
    917
    1018        public function setUp() {
    … …  
    184192        }
    185193
     194        /**
     195         * @ticket 38485
     196         */
     197        public function test_load_muplugin_textdomain_user_locale() {
     198                set_current_screen( 'dashboard' );
     199                wp_set_current_user( self::$user_id );
     200
     201                load_muplugin_textdomain( 'wp-tests-domain' );
     202
     203                set_current_screen( 'front' );
     204
     205                $this->assertSame( get_user_locale(), $this->locale );
     206        }
     207
    186208        public function test_load_plugin_textdomain_site_locale() {
    187209                load_plugin_textdomain( 'wp-tests-domain' );
    … …  
    190212        }
    191213
     214        /**
     215         * @ticket 38485
     216         */
     217        public function test_load_plugin_textdomain_user_locale() {
     218                set_current_screen( 'dashboard' );
     219                wp_set_current_user( self::$user_id );
     220
     221                load_plugin_textdomain( 'wp-tests-domain' );
     222
     223                set_current_screen( 'front' );
     224
     225                $this->assertSame( get_user_locale(), $this->locale );
     226        }
     227
    192228        public function test_load_theme_textdomain_site_locale() {
    193229                load_theme_textdomain( 'wp-tests-domain' );
    … …  
    195231                $this->assertSame( get_locale(), $this->locale );
    196232        }
     233
     234        /**
     235         * @ticket 38485
     236         */
     237        public function test_load_theme_textdomain_user_locale() {
     238                set_current_screen( 'dashboard' );
     239                wp_set_current_user( self::$user_id );
     240
     241                load_theme_textdomain( 'wp-tests-domain' );
     242
     243                set_current_screen( 'front' );
     244
     245                $this->assertSame( get_user_locale(), $this->locale );
     246        }
    197247}
Note: See TracChangeset for help on using the changeset viewer.