Changeset 57350
- Timestamp:
- 01/25/2024 07:51:12 AM (9 months ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-locale-switcher.php
r57337 r57350 284 284 $wp_locale = new WP_Locale(); 285 285 286 WP_Translation_Controller:: instance()->set_locale( $locale );286 WP_Translation_Controller::get_instance()->set_locale( $locale ); 287 287 288 288 /** -
trunk/src/wp-includes/l10n.php
r57339 r57350 798 798 } 799 799 800 $i18n_controller = WP_Translation_Controller:: instance();800 $i18n_controller = WP_Translation_Controller::get_instance(); 801 801 802 802 // Ensures the correct locale is set as the current one, in case it was filtered. … … 912 912 // Since multiple locales are supported, reloadable text domains don't actually need to be unloaded. 913 913 if ( ! $reloadable ) { 914 WP_Translation_Controller:: instance()->unload_textdomain( $domain );914 WP_Translation_Controller::get_instance()->unload_textdomain( $domain ); 915 915 } 916 916 -
trunk/src/wp-includes/l10n/class-wp-translation-controller.php
r57339 r57350 43 43 44 44 /** 45 * Returns the WP_Translation_Controller singleton. 45 * Container for the main instance of the class. 46 * 47 * @since 6.5.0 48 * @var WP_Translation_Controller|null 49 */ 50 private static $instance = null; 51 52 /** 53 * Utility method to retrieve the main instance of the class. 54 * 55 * The instance will be created if it does not exist yet. 46 56 * 47 57 * @since 6.5.0 … … 49 59 * @return WP_Translation_Controller 50 60 */ 51 public static function instance(): WP_Translation_Controller { 52 static $instance; 53 54 if ( ! $instance ) { 55 $instance = new self(); 56 } 57 58 return $instance; 61 public static function get_instance(): WP_Translation_Controller { 62 if ( null === self::$instance ) { 63 self::$instance = new self(); 64 } 65 66 return self::$instance; 59 67 } 60 68 -
trunk/src/wp-settings.php
r57337 r57350 623 623 $GLOBALS['wp_locale_switcher']->init(); 624 624 625 WP_Translation_Controller:: instance()->set_locale( $locale );625 WP_Translation_Controller::get_instance()->set_locale( $locale ); 626 626 627 627 // Load the functions for the active theme, for both parent and child theme if applicable. -
trunk/tests/phpunit/tests/l10n/wpTranslationController.php
r57344 r57350 31 31 $compat_instance = $l10n['wp-tests-domain'] ?? null; 32 32 33 $is_loaded = WP_Translation_Controller:: instance()->is_textdomain_loaded( 'wp-tests-domain' );34 $headers = WP_Translation_Controller:: instance()->get_headers( 'wp-tests-domain' );35 $entries = WP_Translation_Controller:: instance()->get_entries( 'wp-tests-domain' );33 $is_loaded = WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'wp-tests-domain' ); 34 $headers = WP_Translation_Controller::get_instance()->get_headers( 'wp-tests-domain' ); 35 $entries = WP_Translation_Controller::get_instance()->get_entries( 'wp-tests-domain' ); 36 36 37 37 $unload_successful = unload_textdomain( 'wp-tests-domain' ); … … 77 77 $is_loaded_wp = is_textdomain_loaded( 'wp-tests-domain' ); 78 78 79 $is_loaded = WP_Translation_Controller:: instance()->is_textdomain_loaded( 'wp-tests-domain' );79 $is_loaded = WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'wp-tests-domain' ); 80 80 81 81 remove_filter( 'override_load_textdomain', '__return_true' ); … … 103 103 $load_successful = load_textdomain( 'wp-tests-domain', DIR_TESTDATA . '/pomo/simple.mo' ); 104 104 105 $instance = WP_Translation_Controller:: instance();105 $instance = WP_Translation_Controller::get_instance(); 106 106 107 107 $is_loaded = $instance->is_textdomain_loaded( 'wp-tests-domain', 'en_US' ); … … 260 260 $compat_instance = $l10n['wp-tests-domain'] ?? null; 261 261 262 $is_loaded = WP_Translation_Controller:: instance()->is_textdomain_loaded( 'wp-tests-domain' );263 $headers = WP_Translation_Controller:: instance()->get_headers( 'wp-tests-domain' );264 $entries = WP_Translation_Controller:: instance()->get_entries( 'wp-tests-domain' );262 $is_loaded = WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'wp-tests-domain' ); 263 $headers = WP_Translation_Controller::get_instance()->get_headers( 'wp-tests-domain' ); 264 $entries = WP_Translation_Controller::get_instance()->get_entries( 'wp-tests-domain' ); 265 265 266 266 $this->assertNull( $compat_instance, 'Compat instance was not removed' ); … … 282 282 $unload_successful = unload_textdomain( 'wp-tests-domain' ); 283 283 284 $is_loaded = WP_Translation_Controller:: instance()->is_textdomain_loaded( 'wp-tests-domain' );284 $is_loaded = WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'wp-tests-domain' ); 285 285 286 286 remove_filter( 'override_unload_textdomain', '__return_true' ); … … 288 288 $unload_successful_after = unload_textdomain( 'wp-tests-domain' ); 289 289 290 $is_loaded_after = WP_Translation_Controller:: instance()->is_textdomain_loaded( 'wp-tests-domain' );290 $is_loaded_after = WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'wp-tests-domain' ); 291 291 292 292 $this->assertTrue( $unload_successful ); … … 318 318 $actual = __( 'Invalid parameter.' ); 319 319 320 $this->assertTrue( WP_Translation_Controller:: instance()->is_textdomain_loaded() );321 $this->assertTrue( WP_Translation_Controller:: instance()->is_textdomain_loaded( 'default', 'es_ES' ) );320 $this->assertTrue( WP_Translation_Controller::get_instance()->is_textdomain_loaded() ); 321 $this->assertTrue( WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'default', 'es_ES' ) ); 322 322 323 323 restore_previous_locale(); … … 325 325 $actual_2 = __( 'Invalid parameter.' ); 326 326 327 $this->assertTrue( WP_Translation_Controller:: instance()->is_textdomain_loaded( 'default', 'es_ES' ) );327 $this->assertTrue( WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'default', 'es_ES' ) ); 328 328 329 329 $this->assertSame( 'Parámetro no válido. ', $actual ); … … 337 337 */ 338 338 public function test_switch_to_locale_translations_stay_loaded_custom_textdomain() { 339 $this->assertSame( 'en_US', WP_Translation_Controller:: instance()->get_locale() );339 $this->assertSame( 'en_US', WP_Translation_Controller::get_instance()->get_locale() ); 340 340 341 341 require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php'; … … 347 347 $actual = i18n_plugin_test(); 348 348 349 $this->assertSame( 'es_ES', WP_Translation_Controller:: instance()->get_locale() );350 $this->assertTrue( WP_Translation_Controller:: instance()->is_textdomain_loaded( 'internationalized-plugin', 'es_ES' ) );351 $this->assertTrue( WP_Translation_Controller:: instance()->is_textdomain_loaded( 'default', 'es_ES' ) );352 $this->assertFalse( WP_Translation_Controller:: instance()->is_textdomain_loaded( 'foo-bar', 'es_ES' ) );349 $this->assertSame( 'es_ES', WP_Translation_Controller::get_instance()->get_locale() ); 350 $this->assertTrue( WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'internationalized-plugin', 'es_ES' ) ); 351 $this->assertTrue( WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'default', 'es_ES' ) ); 352 $this->assertFalse( WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'foo-bar', 'es_ES' ) ); 353 353 354 354 restore_previous_locale(); … … 356 356 $after = i18n_plugin_test(); 357 357 358 $this->assertTrue( WP_Translation_Controller:: instance()->is_textdomain_loaded( 'internationalized-plugin', 'es_ES' ) );358 $this->assertTrue( WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'internationalized-plugin', 'es_ES' ) ); 359 359 360 360 $this->assertSame( 'This is a dummy plugin', $before ); -
trunk/tests/phpunit/tests/l10n/wpTranslationsConvert.php
r57344 r57350 11 11 */ 12 12 public function test_get_instance() { 13 $instance = WP_Translation_Controller:: instance();14 $instance2 = WP_Translation_Controller:: instance();13 $instance = WP_Translation_Controller::get_instance(); 14 $instance2 = WP_Translation_Controller::get_instance(); 15 15 16 16 $this->assertSame( $instance, $instance2 );
Note: See TracChangeset
for help on using the changeset viewer.