Changeset 49236
- Timestamp:
- 10/20/2020 04:03:58 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 19 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-locale-switcher.php
r46586 r49236 197 197 198 198 foreach ( $domains as $domain ) { 199 199 200 if ( 'default' === $domain ) { 200 201 continue; 201 202 } 202 203 203 unload_textdomain( $domain );204 unload_textdomain( $domain ); 204 205 get_translations_for_domain( $domain ); 205 206 } … … 219 220 */ 220 221 private function change_locale( $locale ) { 221 // Reset translation availability information. 222 _get_path_to_translation( null, true ); 222 global $wp_locale; 223 223 224 224 $this->load_translations( $locale ); 225 225 226 $ GLOBALS['wp_locale']= new WP_Locale();226 $ = new WP_Locale(); 227 227 228 228 /** -
trunk/src/wp-includes/deprecated.php
r49197 r49236 4135 4135 return is_string( $value ) ? addslashes( $value ) : $value; 4136 4136 } 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 -
trunk/src/wp-includes/l10n.php
r49193 r49236 690 690 * @since 1.5.0 691 691 * 692 * @global MO[] $l10n An array of all currently loaded text domains. 693 * @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again. 692 * @global MO[] $l10n An array of all currently loaded text domains. 693 * @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again. 694 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. 694 695 * 695 696 * @param string $domain Text domain. Unique identifier for retrieving translated strings. … … 698 699 */ 699 700 function load_textdomain( $domain, $mofile ) { 700 global $l10n, $l10n_unloaded ;701 global $l10n, $l10n_unloaded; 701 702 702 703 $l10n_unloaded = (array) $l10n_unloaded; … … 756 757 $l10n[ $domain ] = &$mo; 757 758 759 760 761 758 762 return true; 759 763 } … … 763 767 * 764 768 * @since 3.0.0 769 765 770 * 766 771 * @global MO[] $l10n An array of all currently loaded text domains. 767 772 * @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again. 768 773 * 769 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 774 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 775 * @param bool $reloadable Whether the text domain can be loaded just-in-time again. 770 776 * @return bool Whether textdomain was unloaded. 771 777 */ 772 function unload_textdomain( $domain ) {778 function unload_textdomain( $domain ) { 773 779 global $l10n, $l10n_unloaded; 774 780 … … 779 785 * 780 786 * @since 3.0.0 781 * 782 * @param bool $override Whether to override the text domain unloading. Default false. 783 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 784 */ 785 $plugin_override = apply_filters( 'override_unload_textdomain', false, $domain ); 787 * @since 5.6.0 Added the `$reloadable` parameter. 788 * 789 * @param bool $override Whether to override the text domain unloading. Default false. 790 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 791 * @param bool $reloadable Whether the text domain can be loaded just-in-time again. 792 */ 793 $plugin_override = apply_filters( 'override_unload_textdomain', false, $domain, $reloadable ); 786 794 787 795 if ( $plugin_override ) { 788 $l10n_unloaded[ $domain ] = true; 796 if ( ! $reloadable ) { 797 $l10n_unloaded[ $domain ] = true; 798 } 789 799 790 800 return true; … … 795 805 * 796 806 * @since 3.0.0 797 * 798 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 799 */ 800 do_action( 'unload_textdomain', $domain ); 807 * @since 5.6.0 Added the `$reloadable` parameter. 808 * 809 * @param string $domain Text domain. Unique identifier for retrieving translated strings. 810 * @param bool $reloadable Whether the text domain can be loaded just-in-time again. 811 */ 812 do_action( 'unload_textdomain', $domain, $reloadable ); 801 813 802 814 if ( isset( $l10n[ $domain ] ) ) { 803 815 unset( $l10n[ $domain ] ); 804 816 805 $l10n_unloaded[ $domain ] = true; 817 if ( ! $reloadable ) { 818 $l10n_unloaded[ $domain ] = true; 819 } 806 820 807 821 return true; … … 868 882 */ 869 883 function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) { 884 885 870 886 /** 871 887 * Filters a plugin's locale. … … 894 910 } 895 911 912 913 914 896 915 return load_textdomain( $domain, $path . '/' . $mofile ); 897 916 } … … 902 921 * @since 3.0.0 903 922 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first. 923 924 904 925 * 905 926 * @param string $domain Text domain. Unique identifier for retrieving translated strings. … … 909 930 */ 910 931 function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { 932 933 911 934 /** This filter is documented in wp-includes/l10n.php */ 912 935 $locale = apply_filters( 'plugin_locale', determine_locale(), $domain ); … … 921 944 $path = WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ); 922 945 946 947 948 923 949 return load_textdomain( $domain, $path . '/' . $mofile ); 924 950 } … … 934 960 * @since 1.5.0 935 961 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first. 962 963 936 964 * 937 965 * @param string $domain Text domain. Unique identifier for retrieving translated strings. … … 941 969 */ 942 970 function load_theme_textdomain( $domain, $path = false ) { 971 972 943 973 /** 944 974 * Filters a theme's locale. … … 961 991 $path = get_template_directory(); 962 992 } 993 994 995 963 996 964 997 return load_textdomain( $domain, $path . '/' . $locale . '.mo' ); … … 1191 1224 * @access private 1192 1225 * 1193 * @ see get_translations_for_domain()1194 * @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again.1226 * @ 1227 * @global . 1195 1228 * 1196 1229 * @param string $domain Text domain. Unique identifier for retrieving translated strings. … … 1198 1231 */ 1199 1232 function _load_textdomain_just_in_time( $domain ) { 1200 global $l10n_unloaded ;1233 global $l10n_unloaded; 1201 1234 1202 1235 $l10n_unloaded = (array) $l10n_unloaded; … … 1207 1240 } 1208 1241 1209 $translation_path = _get_path_to_translation( $domain ); 1210 if ( false === $translation_path ) { 1242 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 1243 $path = $wp_textdomain_registry->get( $domain ); 1244 if ( ! $path ) { 1211 1245 return false; 1212 1246 } 1213 1247 1214 return load_textdomain( $domain, $translation_path );1215 }1216 1217 /**1218 * Gets the path to a translation file for loading a textdomain just in time.1219 *1220 * Caches the retrieved results internally.1221 *1222 * @since 4.7.01223 * @access private1224 *1225 * @see _load_textdomain_just_in_time()1226 *1227 * @param string $domain Text domain. Unique identifier for retrieving translated strings.1228 * @param bool $reset Whether to reset the internal cache. Used by the switch to locale functionality.1229 * @return string|false The path to the translation file or false if no translation file was found.1230 */1231 function _get_path_to_translation( $domain, $reset = false ) {1232 static $available_translations = array();1233 1234 if ( true === $reset ) {1235 $available_translations = array();1236 }1237 1238 if ( ! isset( $available_translations[ $domain ] ) ) {1239 $available_translations[ $domain ] = _get_path_to_translation_from_lang_dir( $domain );1240 }1241 1242 return $available_translations[ $domain ];1243 }1244 1245 /**1246 * Gets the path to a translation file in the languages directory for the current locale.1247 *1248 * Holds a cached list of available .mo files to improve performance.1249 *1250 * @since 4.7.01251 * @access private1252 *1253 * @see _get_path_to_translation()1254 *1255 * @param string $domain Text domain. Unique identifier for retrieving translated strings.1256 * @return string|false The path to the translation file or false if no translation file was found.1257 */1258 function _get_path_to_translation_from_lang_dir( $domain ) {1259 static $cached_mofiles = null;1260 1261 if ( null === $cached_mofiles ) {1262 $cached_mofiles = array();1263 1264 $locations = array(1265 WP_LANG_DIR . '/plugins',1266 WP_LANG_DIR . '/themes',1267 );1268 1269 foreach ( $locations as $location ) {1270 $mofiles = glob( $location . '/*.mo' );1271 if ( $mofiles ) {1272 $cached_mofiles = array_merge( $cached_mofiles, $mofiles );1273 }1274 }1275 }1276 1277 1248 $locale = determine_locale(); 1278 $mofile = "{$domain}-{$locale}.mo"; 1279 1280 $path = WP_LANG_DIR . '/plugins/' . $mofile; 1281 if ( in_array( $path, $cached_mofiles, true ) ) { 1282 return $path; 1283 } 1284 1285 $path = WP_LANG_DIR . '/themes/' . $mofile; 1286 if ( in_array( $path, $cached_mofiles, true ) ) { 1287 return $path; 1288 } 1289 1290 return false; 1249 1250 // Themes with their language directory outside of WP_LANG_DIR have a different file name. 1251 $template_directory = trailingslashit( get_template_directory() ); 1252 $stylesheet_directory = trailingslashit( get_stylesheet_directory() ); 1253 if ( 0 === strpos( $path, $template_directory ) || 0 === strpos( $path, $stylesheet_directory ) ) { 1254 $mofile = "{$path}{$locale}.mo"; 1255 } else { 1256 $mofile = "{$path}{$domain}-{$locale}.mo"; 1257 } 1258 1259 return load_textdomain( $domain, $mofile ); 1291 1260 } 1292 1261 … … 1298 1267 * @since 2.8.0 1299 1268 * 1300 * @global MO[] $l10n 1269 * @global MO[] $l10n 1301 1270 * 1302 1271 * @param string $domain Text domain. Unique identifier for retrieving translated strings. … … 1322 1291 * @since 3.0.0 1323 1292 * 1324 * @global MO[] $l10n 1293 * @global MO[] $l10n 1325 1294 * 1326 1295 * @param string $domain Text domain. Unique identifier for retrieving translated strings. -
trunk/src/wp-settings.php
r49226 r49236 153 153 // Load the L10n library. 154 154 require_once ABSPATH . WPINC . '/l10n.php'; 155 155 156 require_once ABSPATH . WPINC . '/class-wp-locale.php'; 156 157 require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php'; … … 302 303 $GLOBALS['wp_embed'] = new WP_Embed(); 303 304 305 306 307 308 309 310 311 312 313 314 315 304 316 // Load multisite-specific files. 305 317 if ( is_multisite() ) { -
trunk/tests/phpunit/data/languages/plugins/internationalized-plugin-de_DE.po
r48930 r49236 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: 20+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 \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 18 17 19 "X-Poedit-SearchPath-0: .\n" 18 20 -
trunk/tests/phpunit/data/languages/themes/internationalized-theme-de_DE.po
r48930 r49236 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: 20+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 \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 18 17 19 "X-Poedit-SearchPath-0: .\n" 18 20 -
trunk/tests/phpunit/data/plugins/hello.php
r46586 r49236 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. 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
r49226 r49236 77 77 define( 'DIR_TESTROOT', realpath( dirname( __DIR__ ) ) ); 78 78 79 define( 'WP_LANG_DIR', DIR_TESTDATA . '/languages' ); 79 define( 'WP_LANG_DIR', realpath( DIR_TESTDATA . '/languages' ) ); 80 define( 'WP_PLUGIN_DIR', realpath( DIR_TESTDATA . '/plugins' ) ); 80 81 81 82 if ( ! defined( 'WP_TESTS_FORCE_KNOWN_BUGS' ) ) { -
trunk/tests/phpunit/tests/admin/includesPlugin.php
r49112 r49236 15 15 'Author' => '<a href="http://ma.tt/">Matt Mullenweg</a>', 16 16 'AuthorURI' => 'http://ma.tt/', 17 'Version' => '1. 5.1',17 'Version' => '1.', 18 18 'TextDomain' => 'hello-dolly', 19 19 'DomainPath' => '', -
trunk/tests/phpunit/tests/l10n/loadTextdomain.php
r46586 r49236 25 25 add_filter( 'plugin_locale', array( $this, 'store_locale' ) ); 26 26 add_filter( 'theme_locale', array( $this, 'store_locale' ) ); 27 28 29 30 31 27 32 } 28 33 … … 31 36 remove_filter( 'theme_locale', array( $this, 'store_locale' ) ); 32 37 38 39 40 41 42 33 43 parent::tearDown(); 34 44 } … … 117 127 * @ticket 21319 118 128 */ 119 function test_is_textdomain_is_not_loaded_after_gettext_call_with_no_translations() {129 function test_is_textdomain_is_not_loaded_after_gettext_call_with_no_translations() { 120 130 $this->assertFalse( is_textdomain_loaded( 'wp-tests-domain' ) ); 121 131 __( 'just some string', 'wp-tests-domain' ); … … 123 133 } 124 134 125 function test_override_load_textdomain_noop() {135 function test_override_load_textdomain_noop() { 126 136 add_filter( 'override_load_textdomain', '__return_true' ); 127 137 $load_textdomain = load_textdomain( 'wp-tests-domain', DIR_TESTDATA . '/non-existent-file' ); … … 132 142 } 133 143 134 function test_override_load_textdomain_non_existent_mofile() {144 function test_override_load_textdomain_non_existent_mofile() { 135 145 add_filter( 'override_load_textdomain', array( $this, '_override_load_textdomain_filter' ), 10, 3 ); 136 146 $load_textdomain = load_textdomain( 'wp-tests-domain', WP_LANG_DIR . '/non-existent-file.mo' ); … … 146 156 } 147 157 148 function test_override_load_textdomain_custom_mofile() {158 function test_override_load_textdomain_custom_mofile() { 149 159 add_filter( 'override_load_textdomain', array( $this, '_override_load_textdomain_filter' ), 10, 3 ); 150 160 $load_textdomain = load_textdomain( 'wp-tests-domain', WP_LANG_DIR . '/plugins/internationalized-plugin-de_DE.mo' ); … … 166 176 * @return bool 167 177 */ 168 function _override_load_textdomain_filter( $override, $domain, $file ) {178 function _override_load_textdomain_filter( $override, $domain, $file ) { 169 179 global $l10n; 170 180 -
trunk/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php
r47200 r49236 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 … … 45 47 remove_filter( 'template_root', array( $this, 'filter_theme_root' ) ); 46 48 wp_clean_themes_cache(); 47 unset( $GLOBALS['wp_themes'] ); 48 unset( $GLOBALS['l10n'] ); 49 unset( $GLOBALS['l10n_unloaded'] ); 50 _get_path_to_translation( null, true ); 49 unset( $GLOBALS['wp_themes'], $GLOBALS['l10n'], $GLOBALS['l10n_unloaded'] ); 50 51 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 52 global $wp_textdomain_registry; 53 54 $wp_textdomain_registry->reset(); 51 55 52 56 parent::tearDown(); … … 171 175 /** 172 176 * @ticket 37997 177 173 178 */ 174 179 public function test_plugin_translation_after_switching_locale_twice() { … … 184 189 185 190 $this->assertSame( 'Das ist ein Dummy Plugin', $expected_de_de ); 186 $this->assertSame( ' This is a dummy plugin', $expected_es_es );191 $this->assertSame( '', $expected_es_es ); 187 192 } 188 193 -
trunk/tests/phpunit/tests/l10n/localeSwitcher.php
r48939 r49236 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 tearDown() { 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::tearDown(); … … 389 395 } 390 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 391 468 public function filter_locale() { 392 469 return 'es_ES'; -
trunk/tests/phpunit/tests/theme/themeDir.php
r48937 r49236 163 163 'Theme with Spaces in the Directory', 164 164 'Internationalized Theme', 165 165 166 'camelCase', 166 167 'REST Theme',
Note: See TracChangeset
for help on using the changeset viewer.