WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/03/2016 08:07:08 PM (5 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/loadTextdomainJustInTime.php

    r38961 r39127  
    66 */
    77class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase {
    8 
    9     private $orig_theme_dir;
    10     private $theme_root;
     8    protected $orig_theme_dir;
     9    protected $theme_root;
     10    protected static $user_id;
     11
     12    public static function wpSetUpBeforeClass( $factory ) {
     13        self::$user_id = $factory->user->create( array(
     14            'role'   => 'administrator',
     15            'locale' => 'de_DE',
     16        ) );
     17    }
    1118
    1219    public function setUp() {
     
    172179        $this->assertSame( 'Das ist ein Dummy Theme', $expected );
    173180    }
     181
     182    /**
     183     * @ticket 38485
     184     */
     185    public function test_plugin_translation_with_user_locale() {
     186        require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php';
     187
     188        set_current_screen( 'dashboard' );
     189        wp_set_current_user( self::$user_id );
     190
     191        $expected = i18n_plugin_test();
     192
     193        set_current_screen( 'front' );
     194
     195        $this->assertSame( 'Das ist ein Dummy Plugin', $expected );
     196    }
     197
     198    /**
     199     * @ticket 38485
     200     */
     201    public function test_theme_translation_with_user_locale() {
     202        switch_theme( 'internationalized-theme' );
     203        set_current_screen( 'dashboard' );
     204        wp_set_current_user( self::$user_id );
     205
     206        require_once get_stylesheet_directory() . '/functions.php';
     207
     208        $expected = i18n_theme_test();
     209
     210        set_current_screen( 'front' );
     211        switch_theme( WP_DEFAULT_THEME );
     212
     213        $this->assertSame( 'Das ist ein Dummy Theme', $expected );
     214    }
    174215}
Note: See TracChangeset for help on using the changeset viewer.