Changeset 39127
- Timestamp:
- 11/03/2016 08:07:08 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/l10n.php
r39070 r39127 89 89 function get_user_locale( $user_id = 0 ) { 90 90 $user = false; 91 if ( 0 === $user_id ) {91 if ( 0 === $user_id && function_exists( 'wp_get_current_user' ) ) { 92 92 $user = wp_get_current_user(); 93 93 } elseif ( $user_id instanceof WP_User ) { … … 711 711 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 712 712 */ 713 $locale = apply_filters( 'plugin_locale', get_locale(), $domain );713 $locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain ); 714 714 715 715 $mofile = $domain . '-' . $locale . '.mo'; … … 745 745 function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { 746 746 /** This filter is documented in wp-includes/l10n.php */ 747 $locale = apply_filters( 'plugin_locale', get_locale(), $domain );747 $locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain ); 748 748 749 749 $mofile = $domain . '-' . $locale . '.mo'; … … 784 784 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 785 785 */ 786 $locale = apply_filters( 'theme_locale', get_locale(), $domain );786 $locale = apply_filters( 'theme_locale', is_admin() ? get_user_locale() : get_locale(), $domain ); 787 787 788 788 $mofile = $domain . '-' . $locale . '.mo'; … … 866 866 } 867 867 868 $locale = get_locale();868 $locale = is_admin() ? get_user_locale() : get_locale(); 869 869 $mofile = "{$domain}-{$locale}.mo"; 870 870 -
trunk/tests/phpunit/tests/l10n/loadTextdomain.php
r39125 r39127 7 7 class Tests_L10n_loadTextdomain extends WP_UnitTestCase { 8 8 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 } 9 17 10 18 public function setUp() { … … 184 192 } 185 193 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 186 208 public function test_load_plugin_textdomain_site_locale() { 187 209 load_plugin_textdomain( 'wp-tests-domain' ); … … 190 212 } 191 213 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 192 228 public function test_load_theme_textdomain_site_locale() { 193 229 load_theme_textdomain( 'wp-tests-domain' ); … … 195 231 $this->assertSame( get_locale(), $this->locale ); 196 232 } 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 } 197 247 } -
trunk/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php
r38961 r39127 6 6 */ 7 7 class 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 } 11 18 12 19 public function setUp() { … … 172 179 $this->assertSame( 'Das ist ein Dummy Theme', $expected ); 173 180 } 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 } 174 215 }
Note: See TracChangeset
for help on using the changeset viewer.