Changeset 59430
- Timestamp:
- 11/20/2024 02:48:40 AM (12 days ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-textdomain-registry.php
r58591 r59430 154 154 */ 155 155 public function set_custom_path( $domain, $path ) { 156 // If just-in-time loading was triggered before, reset the entry so it can be tried again. 157 158 if ( isset( $this->all[ $domain ] ) ) { 159 $this->all[ $domain ] = array_filter( $this->all[ $domain ] ); 160 } 161 162 if ( empty( $this->current[ $domain ] ) ) { 163 unset( $this->current[ $domain ] ); 164 } 165 156 166 $this->custom_paths[ $domain ] = rtrim( $path, '/' ); 157 167 } … … 337 347 * using load_plugin_textdomain/load_theme_textdomain, use that one. 338 348 */ 339 if ( 'en_US' !== $locale &&isset( $this->custom_paths[ $domain ] ) ) {349 if ( isset( $this->custom_paths[ $domain ] ) ) { 340 350 $fallback_location = rtrim( $this->custom_paths[ $domain ], '/' ) . '/'; 341 351 $this->set( $domain, $locale, $fallback_location ); -
trunk/src/wp-includes/l10n.php
r59264 r59430 986 986 * @since 6.7.0 Translations are no longer immediately loaded, but handed off to the just-in-time loading mechanism. 987 987 * 988 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. 989 * @global array<string, WP_Translations|NOOP_Translations> $l10n An array of all currently loaded text domains. 990 * 988 991 * @param string $domain Unique identifier for retrieving translated strings 989 992 * @param string|false $deprecated Optional. Deprecated. Use the $plugin_rel_path parameter instead. … … 995 998 function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) { 996 999 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 997 global $wp_textdomain_registry; 1000 /** @var array<string, WP_Translations|NOOP_Translations> $l10n */ 1001 global $wp_textdomain_registry, $l10n; 998 1002 999 1003 if ( ! is_string( $domain ) ) { … … 1012 1016 $wp_textdomain_registry->set_custom_path( $domain, $path ); 1013 1017 1018 // If just-in-time loading was triggered before, reset the entry so it can be tried again. 1019 if ( isset( $l10n[ $domain ] ) && $l10n[ $domain ] instanceof NOOP_Translations ) { 1020 unset( $l10n[ $domain ] ); 1021 } 1022 1014 1023 return true; 1015 1024 } … … 1023 1032 * 1024 1033 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. 1034 * @global array<string, WP_Translations|NOOP_Translations> $l10n An array of all currently loaded text domains. 1025 1035 * 1026 1036 * @param string $domain Text domain. Unique identifier for retrieving translated strings. … … 1031 1041 function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { 1032 1042 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 1033 global $wp_textdomain_registry; 1043 /** @var array<string, WP_Translations|NOOP_Translations> $l10n */ 1044 global $wp_textdomain_registry, $l10n; 1034 1045 1035 1046 if ( ! is_string( $domain ) ) { … … 1040 1051 1041 1052 $wp_textdomain_registry->set_custom_path( $domain, $path ); 1053 1054 // If just-in-time loading was triggered before, reset the entry so it can be tried again. 1055 if ( isset( $l10n[ $domain ] ) && $l10n[ $domain ] instanceof NOOP_Translations ) { 1056 unset( $l10n[ $domain ] ); 1057 } 1042 1058 1043 1059 return true; … … 1057 1073 * 1058 1074 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry. 1075 * @global array<string, WP_Translations|NOOP_Translations> $l10n An array of all currently loaded text domains. 1059 1076 * 1060 1077 * @param string $domain Text domain. Unique identifier for retrieving translated strings. … … 1065 1082 function load_theme_textdomain( $domain, $path = false ) { 1066 1083 /** @var WP_Textdomain_Registry $wp_textdomain_registry */ 1067 global $wp_textdomain_registry; 1084 /** @var array<string, WP_Translations|NOOP_Translations> $l10n */ 1085 global $wp_textdomain_registry, $l10n; 1068 1086 1069 1087 if ( ! is_string( $domain ) ) { … … 1076 1094 1077 1095 $wp_textdomain_registry->set_custom_path( $domain, $path ); 1096 1097 // If just-in-time loading was triggered before, reset the entry so it can be tried again. 1098 if ( isset( $l10n[ $domain ] ) && $l10n[ $domain ] instanceof NOOP_Translations ) { 1099 unset( $l10n[ $domain ] ); 1100 } 1078 1101 1079 1102 return true; -
trunk/tests/phpunit/data/plugins/custom-internationalized-plugin/custom-internationalized-plugin.php
r53874 r59430 8 8 */ 9 9 10 load_plugin_textdomain( 'custom-internationalized-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); 10 function custom_i18n_load_textdomain() { 11 load_plugin_textdomain( 'custom-internationalized-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); 12 } 13 14 add_action( 'init', 'custom_i18n_load_textdomain' ); 11 15 12 16 function custom_i18n_plugin_test() { -
trunk/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php
r57516 r59430 343 343 $this->assertSame( 1, $filter->get_call_count() ); 344 344 } 345 346 /** 347 * @ticket 44937 348 * @ticket 62337 349 * 350 * @covers ::load_plugin_textdomain 351 * @covers ::is_textdomain_loaded 352 * @covers WP_Textdomain_Registry::set_custom_path 353 */ 354 public function test_plugin_translation_should_be_translated_when_calling_load_plugin_textdomain_too_late() { 355 require_once DIR_TESTDATA . '/plugins/custom-internationalized-plugin/custom-internationalized-plugin.php'; 356 357 add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) ); 358 359 $is_textdomain_loaded_before = is_textdomain_loaded( 'custom-internationalized-plugin' ); 360 $output_before = custom_i18n_plugin_test(); 361 362 $is_textdomain_loaded_middle = is_textdomain_loaded( 'custom-internationalized-plugin' ); 363 364 custom_i18n_load_textdomain(); 365 366 $output_after = custom_i18n_plugin_test(); 367 $is_textdomain_loaded_after = is_textdomain_loaded( 'custom-internationalized-plugin' ); 368 369 $this->assertFalse( $is_textdomain_loaded_before ); 370 $this->assertFalse( $is_textdomain_loaded_middle ); 371 $this->assertSame( 'This is a dummy plugin', $output_before ); 372 $this->assertSame( 'Das ist ein Dummy Plugin', $output_after ); 373 $this->assertTrue( $is_textdomain_loaded_after ); 374 } 345 375 } -
trunk/tests/phpunit/tests/l10n/wpLocaleSwitcher.php
r57337 r59430 494 494 require_once DIR_TESTDATA . '/plugins/custom-internationalized-plugin/custom-internationalized-plugin.php'; 495 495 496 custom_i18n_load_textdomain(); 497 496 498 $actual = custom_i18n_plugin_test(); 497 499 -
trunk/tests/phpunit/tests/l10n/wpTextdomainRegistry.php
r57831 r59430 40 40 'Incorrect availability status for textdomain with custom path' 41 41 ); 42 $this->assertFalse( 42 $this->assertSame( 43 WP_LANG_DIR . '/bar/', 43 44 $this->instance->get( 'foo', 'en_US' ), 44 'Should notreturn custom path for textdomain and en_US locale'45 'Should return custom path for textdomain and en_US locale' 45 46 ); 46 47 $this->assertSame(
Note: See TracChangeset
for help on using the changeset viewer.