Changeset 53874
- Timestamp:
- 08/11/2022 12:37:05 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 19 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-locale-switcher.php
r49566 r53874 197 197 198 198 foreach ( $domains as $domain ) { 199 // The default text domain is handled by `load_default_textdomain()`. 199 200 if ( 'default' === $domain ) { 200 201 continue; 201 202 } 202 203 203 unload_textdomain( $domain ); 204 // Unload current text domain but allow them to be reloaded 205 // after switching back or to another locale. 206 unload_textdomain( $domain, true ); 204 207 get_translations_for_domain( $domain ); 205 208 } … … 219 222 */ 220 223 private function change_locale( $locale ) { 221 // Reset translation availability information. 222 _get_path_to_translation( null, true ); 224 global $wp_locale; 223 225 224 226 $this->load_translations( $locale ); 225 227 226 $ GLOBALS['wp_locale']= new WP_Locale();228 $wp_locale = new WP_Locale(); 227 229 228 230 /** -
trunk/src/wp-includes/deprecated.php
r53715 r53874 4361 4361 return false; 4362 4362 } 4363 4364 /** 4365 * Gets the path to a translation file for loading a textdomain just in time. 4366 * 4367 * Caches the retrieved results internally. 4368 * 4369 * @since 4.7.0 4370 * @deprecated 6.1.0 4371 * @access private 4372 * 4373 * @see _load_textdomain_just_in_time() 4374 * 4375 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 4376 * @param bool $reset Whether to reset the internal cache. Used by the switch to locale functionality. 4377 * @return string|false The path to the translation file or false if no translation file was found. 4378 */ 4379 function _get_path_to_translation( $domain, $reset = false ) { 4380 _deprecated_function( __FUNCTION__, '6.1.0', 'WP_Textdomain_Registry' ); 4381 4382 static $available_translations = array(); 4383 4384 if ( true === $reset ) { 4385 $available_translations = array(); 4386 } 4387 4388 if ( ! isset( $available_translations[ $domain ] ) ) { 4389 $available_translations[ $domain ] = _get_path_to_translation_from_lang_dir( $domain ); 4390 } 4391 4392 return $available_translations[ $domain ]; 4393 } 4394 4395 /** 4396 * Gets the path to a translation file in the languages directory for the current locale. 4397 * 4398 * Holds a cached list of available .mo files to improve performance. 4399 * 4400 * @since 4.7.0 4401 * @deprecated 6.1.0 4402 * @access private 4403 * 4404 * @see _get_path_to_translation() 4405 * 4406 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 4407 * @return string|false The path to the translation file or false if no translation file was found. 4408 */ 4409 function _get_path_to_translation_from_lang_dir( $domain ) { 4410 _deprecated_function( __FUNCTION__, '6.1.0', 'WP_Textdomain_Registry' ); 4411 4412 static $cached_mofiles = null; 4413 4414 if ( null === $cached_mofiles ) { 4415 $cached_mofiles = array(); 4416 4417 $locations = array( 4418 WP_LANG_DIR . '/plugins', 4419 WP_LANG_DIR . '/themes', 4420 ); 4421 4422 foreach ( $locations as $location ) { 4423 $mofiles = glob( $location . '/*.mo' ); 4424 if ( $mofiles ) { 4425 $cached_mofiles = array_merge( $cached_mofiles, $mofiles ); 4426 } 4427 } 4428 } 4429 4430 $locale = determine_locale(); 4431 $mofile = "{$domain}-{$locale}.mo"; 4432 4433 $path = WP_LANG_DIR . '/plugins/' . $mofile; 4434 if ( in_array( $path, $cached_mofiles, true ) ) { 4435 return $path; 4436 } 4437 4438 $path = WP_LANG_DIR . '/themes/' . $mofile; 4439 if ( in_array( $path, $cached_mofiles, true ) ) { 4440 return $path; 4441 } 4442 4443 return false; 4444 } -
trunk/src/wp-includes/l10n.php
r53702 r53874 705 705 * 706 706 * @since 1.5.0 707 * 708 * @global MO[] $l10n An array of all currently loaded text domains. 709 * @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again. 707 * @since 6.1.0 Added the `$locale` parameter. 708 * 709 * @global MO[] $l10n An array of all currently loaded text domains. 710 * @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again. 711 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. 710 712 * 711 713 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 712 714 * @param string $mofile Path to the .mo file. 715 * @param string $locale Optional. Locale. Default is the current locale. 713 716 * @return bool True on success, false on failure. 714 717 */ 715 function load_textdomain( $domain, $mofile ) { 716 global $l10n, $l10n_unloaded; 718 function load_textdomain( $domain, $mofile, $locale = null ) { 719 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 720 global $l10n, $l10n_unloaded, $wp_textdomain_registry; 717 721 718 722 $l10n_unloaded = (array) $l10n_unloaded; … … 759 763 } 760 764 765 if ( ! $locale ) { 766 $locale = determine_locale(); 767 } 768 761 769 $mo = new MO(); 762 770 if ( ! $mo->import_from_file( $mofile ) ) { 771 $wp_textdomain_registry->set( $domain, $locale, false ); 772 763 773 return false; 764 774 } … … 772 782 $l10n[ $domain ] = &$mo; 773 783 784 $wp_textdomain_registry->set( $domain, $locale, dirname( $mofile ) ); 785 774 786 return true; 775 787 } … … 779 791 * 780 792 * @since 3.0.0 793 * @since 6.1.0 Added the `$reloadable` parameter. 781 794 * 782 795 * @global MO[] $l10n An array of all currently loaded text domains. 783 796 * @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again. 784 797 * 785 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 798 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 799 * @param bool $reloadable Whether the text domain can be loaded just-in-time again. 786 800 * @return bool Whether textdomain was unloaded. 787 801 */ 788 function unload_textdomain( $domain ) {802 function unload_textdomain( $domain, $reloadable = false ) { 789 803 global $l10n, $l10n_unloaded; 790 804 … … 795 809 * 796 810 * @since 3.0.0 797 * 798 * @param bool $override Whether to override the text domain unloading. Default false. 799 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 800 */ 801 $plugin_override = apply_filters( 'override_unload_textdomain', false, $domain ); 811 * @since 6.1.0 Added the `$reloadable` parameter. 812 * 813 * @param bool $override Whether to override the text domain unloading. Default false. 814 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 815 * @param bool $reloadable Whether the text domain can be loaded just-in-time again. 816 */ 817 $plugin_override = apply_filters( 'override_unload_textdomain', false, $domain, $reloadable ); 802 818 803 819 if ( $plugin_override ) { 804 $l10n_unloaded[ $domain ] = true; 820 if ( ! $reloadable ) { 821 $l10n_unloaded[ $domain ] = true; 822 } 805 823 806 824 return true; … … 811 829 * 812 830 * @since 3.0.0 813 * 814 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 815 */ 816 do_action( 'unload_textdomain', $domain ); 831 * @since 6.1.0 Added the `$reloadable` parameter. 832 * 833 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 834 * @param bool $reloadable Whether the text domain can be loaded just-in-time again. 835 */ 836 do_action( 'unload_textdomain', $domain, $reloadable ); 817 837 818 838 if ( isset( $l10n[ $domain ] ) ) { 819 839 unset( $l10n[ $domain ] ); 820 840 821 $l10n_unloaded[ $domain ] = true; 841 if ( ! $reloadable ) { 842 $l10n_unloaded[ $domain ] = true; 843 } 822 844 823 845 return true; … … 848 870 unload_textdomain( 'default' ); 849 871 850 $return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" );872 $return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo", $locale ); 851 873 852 874 if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( WP_LANG_DIR . "/admin-$locale.mo" ) ) { 853 load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo" );875 load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo", $locale ); 854 876 return $return; 855 877 } 856 878 857 879 if ( is_admin() || wp_installing() || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) { 858 load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" );880 load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo", $locale ); 859 881 } 860 882 861 883 if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) { 862 load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo" );884 load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo", $locale ); 863 885 } 864 886 … … 884 906 */ 885 907 function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) { 908 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 909 global $wp_textdomain_registry; 910 886 911 /** 887 912 * Filters a plugin's locale. … … 897 922 898 923 // Try to load from the languages directory first. 899 if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) {924 if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile, $locale ) ) { 900 925 return true; 901 926 } … … 910 935 } 911 936 912 return load_textdomain( $domain, $path . '/' . $mofile ); 937 $wp_textdomain_registry->set( $domain, $locale, $path ); 938 939 return load_textdomain( $domain, $path . '/' . $mofile, $locale ); 913 940 } 914 941 … … 918 945 * @since 3.0.0 919 946 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first. 947 * 948 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. 920 949 * 921 950 * @param string $domain Text domain. Unique identifier for retrieving translated strings. … … 925 954 */ 926 955 function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { 956 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 957 global $wp_textdomain_registry; 958 927 959 /** This filter is documented in wp-includes/l10n.php */ 928 960 $locale = apply_filters( 'plugin_locale', determine_locale(), $domain ); … … 931 963 932 964 // Try to load from the languages directory first. 933 if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) {965 if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile, $locale ) ) { 934 966 return true; 935 967 } … … 937 969 $path = WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ); 938 970 939 return load_textdomain( $domain, $path . '/' . $mofile ); 971 $wp_textdomain_registry->set( $domain, $locale, $path ); 972 973 return load_textdomain( $domain, $path . '/' . $mofile, $locale ); 940 974 } 941 975 … … 950 984 * @since 1.5.0 951 985 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first. 986 * 987 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. 952 988 * 953 989 * @param string $domain Text domain. Unique identifier for retrieving translated strings. … … 957 993 */ 958 994 function load_theme_textdomain( $domain, $path = false ) { 995 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 996 global $wp_textdomain_registry; 997 959 998 /** 960 999 * Filters a theme's locale. … … 970 1009 971 1010 // Try to load from the languages directory first. 972 if ( load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile ) ) {1011 if ( load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile, $locale ) ) { 973 1012 return true; 974 1013 } … … 978 1017 } 979 1018 980 return load_textdomain( $domain, $path . '/' . $locale . '.mo' ); 1019 $wp_textdomain_registry->set( $domain, $locale, $path ); 1020 1021 return load_textdomain( $domain, $path . '/' . $locale . '.mo', $locale ); 981 1022 } 982 1023 … … 1199 1240 1200 1241 /** 1201 * Loads plugin and theme text domains just-in-time.1242 * Loads plugin and theme text domains just-in-time. 1202 1243 * 1203 1244 * When a textdomain is encountered for the first time, we try to load … … 1208 1249 * @access private 1209 1250 * 1210 * @ see get_translations_for_domain()1211 * @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again.1251 * @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again. 1252 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. 1212 1253 * 1213 1254 * @param string $domain Text domain. Unique identifier for retrieving translated strings. … … 1215 1256 */ 1216 1257 function _load_textdomain_just_in_time( $domain ) { 1217 global $l10n_unloaded; 1258 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 1259 global $l10n_unloaded, $wp_textdomain_registry; 1218 1260 1219 1261 $l10n_unloaded = (array) $l10n_unloaded; … … 1224 1266 } 1225 1267 1226 $translation_path = _get_path_to_translation( $domain ); 1227 if ( false === $translation_path ) { 1268 if ( $wp_textdomain_registry->has( $domain ) && ! $wp_textdomain_registry->get_current( $domain ) ) { 1228 1269 return false; 1229 1270 } 1230 1271 1231 return load_textdomain( $domain, $translation_path );1232 }1233 1234 /**1235 * Gets the path to a translation file for loading a textdomain just in time.1236 *1237 * Caches the retrieved results internally.1238 *1239 * @since 4.7.01240 * @access private1241 *1242 * @see _load_textdomain_just_in_time()1243 *1244 * @param string $domain Text domain. Unique identifier for retrieving translated strings.1245 * @param bool $reset Whether to reset the internal cache. Used by the switch to locale functionality.1246 * @return string|false The path to the translation file or false if no translation file was found.1247 */1248 function _get_path_to_translation( $domain, $reset = false ) {1249 static $available_translations = array();1250 1251 if ( true === $reset ) {1252 $available_translations = array();1253 }1254 1255 if ( ! isset( $available_translations[ $domain ] ) ) {1256 $available_translations[ $domain ] = _get_path_to_translation_from_lang_dir( $domain );1257 }1258 1259 return $available_translations[ $domain ];1260 }1261 1262 /**1263 * Gets the path to a translation file in the languages directory for the current locale.1264 *1265 * Holds a cached list of available .mo files to improve performance.1266 *1267 * @since 4.7.01268 * @access private1269 *1270 * @see _get_path_to_translation()1271 *1272 * @param string $domain Text domain. Unique identifier for retrieving translated strings.1273 * @return string|false The path to the translation file or false if no translation file was found.1274 */1275 function _get_path_to_translation_from_lang_dir( $domain ) {1276 static $cached_mofiles = null;1277 1278 if ( null === $cached_mofiles ) {1279 $cached_mofiles = array();1280 1281 $locations = array(1282 WP_LANG_DIR . '/plugins',1283 WP_LANG_DIR . '/themes',1284 );1285 1286 foreach ( $locations as $location ) {1287 $mofiles = glob( $location . '/*.mo' );1288 if ( $mofiles ) {1289 $cached_mofiles = array_merge( $cached_mofiles, $mofiles );1290 }1291 }1292 }1293 1294 1272 $locale = determine_locale(); 1295 $mofile = "{$domain}-{$locale}.mo"; 1296 1297 $path = WP_LANG_DIR . '/plugins/' . $mofile; 1298 if ( in_array( $path, $cached_mofiles, true ) ) { 1299 return $path; 1300 } 1301 1302 $path = WP_LANG_DIR . '/themes/' . $mofile; 1303 if ( in_array( $path, $cached_mofiles, true ) ) { 1304 return $path; 1305 } 1306 1307 return false; 1273 $path = $wp_textdomain_registry->get( $domain, $locale ); 1274 if ( ! $path ) { 1275 return false; 1276 } 1277 // Themes with their language directory outside of WP_LANG_DIR have a different file name. 1278 $template_directory = trailingslashit( get_template_directory() ); 1279 $stylesheet_directory = trailingslashit( get_stylesheet_directory() ); 1280 if ( str_starts_with( $path, $template_directory ) || str_starts_with( $path, $stylesheet_directory ) ) { 1281 $mofile = "{$path}{$locale}.mo"; 1282 } else { 1283 $mofile = "{$path}{$domain}-{$locale}.mo"; 1284 } 1285 1286 return load_textdomain( $domain, $mofile, $locale ); 1308 1287 } 1309 1288 … … 1315 1294 * @since 2.8.0 1316 1295 * 1317 * @global MO[] $l10n 1296 * @global MO[] $l10n An array of all currently loaded text domains. 1318 1297 * 1319 1298 * @param string $domain Text domain. Unique identifier for retrieving translated strings. … … 1339 1318 * @since 3.0.0 1340 1319 * 1341 * @global MO[] $l10n 1320 * @global MO[] $l10n An array of all currently loaded text domains. 1342 1321 * 1343 1322 * @param string $domain Text domain. Unique identifier for retrieving translated strings. -
trunk/src/wp-settings.php
r53152 r53874 153 153 // Load the L10n library. 154 154 require_once ABSPATH . WPINC . '/l10n.php'; 155 require_once ABSPATH . WPINC . '/class-wp-textdomain-registry.php'; 155 156 require_once ABSPATH . WPINC . '/class-wp-locale.php'; 156 157 require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php'; … … 335 336 $GLOBALS['wp_embed'] = new WP_Embed(); 336 337 338 /** 339 * WordPress Textdomain Registry object. 340 * 341 * Used to support just-in-time translations for manually loaded text domains. 342 * 343 * @since 6.1.0 344 * 345 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. 346 */ 347 $GLOBALS['wp_textdomain_registry'] = new WP_Textdomain_Registry(); 348 337 349 // Load multisite-specific files. 338 350 if ( is_multisite() ) { -
trunk/tests/phpunit/data/languages/plugins/internationalized-plugin-de_DE.po
r49566 r53874 3 3 "Project-Id-Version: \n" 4 4 "POT-Creation-Date: 2015-12-31 16:31+0100\n" 5 "PO-Revision-Date: 20 16-10-26 00:02+0200\n"5 "PO-Revision-Date: 2020-10-20 17:11+0200\n" 6 6 "Language: de_DE\n" 7 7 "MIME-Version: 1.0\n" 8 8 "Content-Type: text/plain; charset=UTF-8\n" 9 9 "Content-Transfer-Encoding: 8bit\n" 10 "X-Generator: Poedit 1.8.10\n"10 "X-Generator: Poedit 2.4.1\n" 11 11 "X-Poedit-Basepath: .\n" 12 12 "Plural-Forms: nplurals=2; plural=(n != 1);\n" … … 15 15 "esc_html_x:1,2c\n" 16 16 "X-Textdomain-Support: yes\n" 17 "Language-Team: \n" 18 "Last-Translator: \n" 17 19 "X-Poedit-SearchPath-0: .\n" 18 20 -
trunk/tests/phpunit/data/languages/themes/internationalized-theme-de_DE.po
r49566 r53874 3 3 "Project-Id-Version: \n" 4 4 "POT-Creation-Date: 2015-12-31 16:38+0100\n" 5 "PO-Revision-Date: 20 16-10-26 00:02+0200\n"5 "PO-Revision-Date: 2020-10-20 17:09+0200\n" 6 6 "Language: de_DE\n" 7 7 "MIME-Version: 1.0\n" 8 8 "Content-Type: text/plain; charset=UTF-8\n" 9 9 "Content-Transfer-Encoding: 8bit\n" 10 "X-Generator: Poedit 1.8.10\n"10 "X-Generator: Poedit 2.4.1\n" 11 11 "X-Poedit-Basepath: .\n" 12 12 "Plural-Forms: nplurals=2; plural=(n != 1);\n" … … 15 15 "esc_html_x:1,2c\n" 16 16 "X-Textdomain-Support: yes\n" 17 "Last-Translator: \n" 18 "Language-Team: \n" 17 19 "X-Poedit-SearchPath-0: .\n" 18 20 -
trunk/tests/phpunit/data/plugins/hello.php
r49566 r53874 5 5 Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page. 6 6 Author: Matt Mullenweg 7 Version: 1. 5.17 Version: 1.7.2 8 8 Author URI: http://ma.tt/ 9 9 Text Domain: hello-dolly 10 10 11 11 */ 12 13 // Test for14 ?> -
trunk/tests/phpunit/includes/bootstrap.php
r52009 r53874 216 216 define( 'DIR_TESTROOT', realpath( dirname( __DIR__ ) ) ); 217 217 218 define( 'WP_LANG_DIR', DIR_TESTDATA . '/languages' ); 218 define( 'WP_LANG_DIR', realpath( DIR_TESTDATA . '/languages' ) ); 219 define( 'WP_PLUGIN_DIR', realpath( DIR_TESTDATA . '/plugins' ) ); 219 220 220 221 if ( ! defined( 'WP_TESTS_FORCE_KNOWN_BUGS' ) ) { -
trunk/tests/phpunit/tests/admin/includesPlugin.php
r53104 r53874 23 23 'Author' => '<a href="http://ma.tt/">Matt Mullenweg</a>', 24 24 'AuthorURI' => 'http://ma.tt/', 25 'Version' => '1. 5.1',25 'Version' => '1.7.2', 26 26 'TextDomain' => 'hello-dolly', 27 27 'DomainPath' => '', -
trunk/tests/phpunit/tests/l10n/loadTextdomain.php
r53866 r53874 25 25 add_filter( 'plugin_locale', array( $this, 'store_locale' ) ); 26 26 add_filter( 'theme_locale', array( $this, 'store_locale' ) ); 27 28 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 29 global $wp_textdomain_registry; 30 31 $wp_textdomain_registry->reset(); 32 } 33 34 public function tear_down() { 35 36 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 37 global $wp_textdomain_registry; 38 39 $wp_textdomain_registry->reset(); 40 41 parent::tear_down(); 27 42 } 28 43 -
trunk/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php
r53866 r53874 33 33 add_filter( 'template_root', array( $this, 'filter_theme_root' ) ); 34 34 wp_clean_themes_cache(); 35 unset( $GLOBALS['wp_themes'] ); 36 unset( $GLOBALS['l10n'] ); 37 unset( $GLOBALS['l10n_unloaded'] ); 38 _get_path_to_translation( null, true ); 35 unset( $GLOBALS['wp_themes'], $GLOBALS['l10n'], $GLOBALS['l10n_unloaded'] ); 36 37 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 38 global $wp_textdomain_registry; 39 40 $wp_textdomain_registry->reset(); 39 41 } 40 42 … … 42 44 $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir; 43 45 wp_clean_themes_cache(); 44 unset( $GLOBALS['wp_themes'] ); 45 unset( $GLOBALS['l10n'] ); 46 unset( $GLOBALS['l10n_unloaded'] ); 47 _get_path_to_translation( null, true ); 46 unset( $GLOBALS['wp_themes'], $GLOBALS['l10n'], $GLOBALS['l10n_unloaded'] ); 47 48 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 49 global $wp_textdomain_registry; 50 51 $wp_textdomain_registry->reset(); 48 52 49 53 parent::tear_down(); … … 178 182 /** 179 183 * @ticket 37997 184 * @ticket 39210 180 185 * 181 186 * @covers ::switch_to_locale … … 193 198 194 199 $this->assertSame( 'Das ist ein Dummy Plugin', $actual_de_de ); 195 $this->assertSame( ' This is a dummy plugin', $actual_es_es );200 $this->assertSame( 'Este es un plugin dummy', $actual_es_es ); 196 201 } 197 202 -
trunk/tests/phpunit/tests/l10n/wpLocaleSwitcher.php
r53866 r53874 23 23 $this->previous_locale = ''; 24 24 25 unset( $GLOBALS['l10n'] ); 26 unset( $GLOBALS['l10n_unloaded'] ); 27 _get_path_to_translation( null, true ); 25 unset( $GLOBALS['l10n'], $GLOBALS['l10n_unloaded'] ); 26 27 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 28 global $wp_textdomain_registry; 29 30 $wp_textdomain_registry->reset(); 28 31 } 29 32 30 33 public function tear_down() { 31 unset( $GLOBALS['l10n'] ); 32 unset( $GLOBALS['l10n_unloaded'] ); 33 _get_path_to_translation( null, true ); 34 unset( $GLOBALS['l10n'], $GLOBALS['l10n_unloaded'] ); 35 36 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 37 global $wp_textdomain_registry; 38 39 $wp_textdomain_registry->reset(); 34 40 35 41 parent::tear_down(); … … 459 465 } 460 466 467 /** 468 * @ticket 39210 469 */ 470 public function test_switch_reloads_plugin_translations_outside_wp_lang_dir() { 471 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 472 global $wp_locale_switcher, $wp_textdomain_registry; 473 474 $locale_switcher = clone $wp_locale_switcher; 475 476 $wp_locale_switcher = new WP_Locale_Switcher(); 477 $wp_locale_switcher->init(); 478 479 require_once DIR_TESTDATA . '/plugins/custom-internationalized-plugin/custom-internationalized-plugin.php'; 480 481 $registry_value = $wp_textdomain_registry->get( 'custom-internationalized-plugin', determine_locale() ); 482 483 $actual = custom_i18n_plugin_test(); 484 485 switch_to_locale( 'es_ES' ); 486 switch_to_locale( 'de_DE' ); 487 488 $actual_de_de = custom_i18n_plugin_test(); 489 490 restore_previous_locale(); 491 492 $actual_es_es = custom_i18n_plugin_test(); 493 494 restore_current_locale(); 495 496 $wp_locale_switcher = $locale_switcher; 497 498 $this->assertSame( 'This is a dummy plugin', $actual ); 499 $this->assertSame( WP_PLUGIN_DIR . '/custom-internationalized-plugin/languages/', $registry_value ); 500 $this->assertSame( 'Das ist ein Dummy Plugin', $actual_de_de ); 501 $this->assertSame( 'Este es un plugin dummy', $actual_es_es ); 502 } 503 504 /** 505 * @ticket 39210 506 */ 507 public function test_switch_reloads_theme_translations_outside_wp_lang_dir() { 508 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 509 global $wp_locale_switcher, $wp_textdomain_registry; 510 511 $locale_switcher = clone $wp_locale_switcher; 512 513 $wp_locale_switcher = new WP_Locale_Switcher(); 514 $wp_locale_switcher->init(); 515 516 switch_theme( 'custom-internationalized-theme' ); 517 518 require_once get_stylesheet_directory() . '/functions.php'; 519 520 $registry_value = $wp_textdomain_registry->get( 'custom-internationalized-theme', determine_locale() ); 521 522 $actual = custom_i18n_theme_test(); 523 524 switch_to_locale( 'es_ES' ); 525 switch_to_locale( 'de_DE' ); 526 527 $actual_de_de = custom_i18n_theme_test(); 528 529 restore_previous_locale(); 530 531 $actual_es_es = custom_i18n_theme_test(); 532 533 restore_current_locale(); 534 535 $wp_locale_switcher = $locale_switcher; 536 537 $this->assertSame( get_template_directory() . '/languages/', $registry_value ); 538 $this->assertSame( 'This is a dummy theme', $actual ); 539 $this->assertSame( 'Das ist ein Dummy Theme', $actual_de_de ); 540 $this->assertSame( 'Este es un tema dummy', $actual_es_es ); 541 } 542 461 543 public function filter_locale() { 462 544 return 'es_ES'; -
trunk/tests/phpunit/tests/theme/themeDir.php
r53416 r53874 160 160 'Theme with Spaces in the Directory', 161 161 'Internationalized Theme', 162 'Custom Internationalized Theme', 162 163 'camelCase', 163 164 'REST Theme',
Note: See TracChangeset
for help on using the changeset viewer.