Make WordPress Core

Changeset 57350


Ignore:
Timestamp:
01/25/2024 07:51:12 AM (9 months ago)
Author:
swissspidy
Message:

I18N: Rename WP_Translation_Controller::instance() method to get_instance().

This improves consistency as get_instance() is more commonly used in core.

See #59656.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-locale-switcher.php

    r57337 r57350  
    284284        $wp_locale = new WP_Locale();
    285285
    286         WP_Translation_Controller::instance()->set_locale( $locale );
     286        WP_Translation_Controller::get_instance()->set_locale( $locale );
    287287
    288288        /**
  • trunk/src/wp-includes/l10n.php

    r57339 r57350  
    798798    }
    799799
    800     $i18n_controller = WP_Translation_Controller::instance();
     800    $i18n_controller = WP_Translation_Controller::get_instance();
    801801
    802802    // Ensures the correct locale is set as the current one, in case it was filtered.
     
    912912    // Since multiple locales are supported, reloadable text domains don't actually need to be unloaded.
    913913    if ( ! $reloadable ) {
    914         WP_Translation_Controller::instance()->unload_textdomain( $domain );
     914        WP_Translation_Controller::get_instance()->unload_textdomain( $domain );
    915915    }
    916916
  • trunk/src/wp-includes/l10n/class-wp-translation-controller.php

    r57339 r57350  
    4343
    4444    /**
    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.
    4656     *
    4757     * @since 6.5.0
     
    4959     * @return WP_Translation_Controller
    5060     */
    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;
    5967    }
    6068
  • trunk/src/wp-settings.php

    r57337 r57350  
    623623$GLOBALS['wp_locale_switcher']->init();
    624624
    625 WP_Translation_Controller::instance()->set_locale( $locale );
     625WP_Translation_Controller::get_instance()->set_locale( $locale );
    626626
    627627// Load the functions for the active theme, for both parent and child theme if applicable.
  • trunk/tests/phpunit/tests/l10n/wpTranslationController.php

    r57344 r57350  
    3131        $compat_instance = $l10n['wp-tests-domain'] ?? null;
    3232
    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' );
    3636
    3737        $unload_successful = unload_textdomain( 'wp-tests-domain' );
     
    7777        $is_loaded_wp = is_textdomain_loaded( 'wp-tests-domain' );
    7878
    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' );
    8080
    8181        remove_filter( 'override_load_textdomain', '__return_true' );
     
    103103        $load_successful = load_textdomain( 'wp-tests-domain', DIR_TESTDATA . '/pomo/simple.mo' );
    104104
    105         $instance = WP_Translation_Controller::instance();
     105        $instance = WP_Translation_Controller::get_instance();
    106106
    107107        $is_loaded = $instance->is_textdomain_loaded( 'wp-tests-domain', 'en_US' );
     
    260260        $compat_instance = $l10n['wp-tests-domain'] ?? null;
    261261
    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' );
    265265
    266266        $this->assertNull( $compat_instance, 'Compat instance was not removed' );
     
    282282        $unload_successful = unload_textdomain( 'wp-tests-domain' );
    283283
    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' );
    285285
    286286        remove_filter( 'override_unload_textdomain', '__return_true' );
     
    288288        $unload_successful_after = unload_textdomain( 'wp-tests-domain' );
    289289
    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' );
    291291
    292292        $this->assertTrue( $unload_successful );
     
    318318        $actual = __( 'Invalid parameter.' );
    319319
    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' ) );
    322322
    323323        restore_previous_locale();
     
    325325        $actual_2 = __( 'Invalid parameter.' );
    326326
    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' ) );
    328328
    329329        $this->assertSame( 'Parámetro no válido. ', $actual );
     
    337337     */
    338338    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() );
    340340
    341341        require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php';
     
    347347        $actual = i18n_plugin_test();
    348348
    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' ) );
    353353
    354354        restore_previous_locale();
     
    356356        $after = i18n_plugin_test();
    357357
    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' ) );
    359359
    360360        $this->assertSame( 'This is a dummy plugin', $before );
  • trunk/tests/phpunit/tests/l10n/wpTranslationsConvert.php

    r57344 r57350  
    1111     */
    1212    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();
    1515
    1616        $this->assertSame( $instance, $instance2 );
Note: See TracChangeset for help on using the changeset viewer.