mirror of
git://develop.git.wordpress.org/
synced 2025-01-17 21:08:44 +01:00
I18N: Rename WP_Translation_Controller::instance()
method to get_instance()
.
This improves consistency as `get_instance()` is more commonly used in core. See #59656. git-svn-id: https://develop.svn.wordpress.org/trunk@57350 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
fa441afd6e
commit
a61525049f
@ -283,7 +283,7 @@ class WP_Locale_Switcher {
|
||||
|
||||
$wp_locale = new WP_Locale();
|
||||
|
||||
WP_Translation_Controller::instance()->set_locale( $locale );
|
||||
WP_Translation_Controller::get_instance()->set_locale( $locale );
|
||||
|
||||
/**
|
||||
* Fires when the locale is switched to or restored.
|
||||
|
@ -797,7 +797,7 @@ function load_textdomain( $domain, $mofile, $locale = null ) {
|
||||
$locale = determine_locale();
|
||||
}
|
||||
|
||||
$i18n_controller = WP_Translation_Controller::instance();
|
||||
$i18n_controller = WP_Translation_Controller::get_instance();
|
||||
|
||||
// Ensures the correct locale is set as the current one, in case it was filtered.
|
||||
$i18n_controller->set_locale( $locale );
|
||||
@ -911,7 +911,7 @@ function unload_textdomain( $domain, $reloadable = false ) {
|
||||
|
||||
// Since multiple locales are supported, reloadable text domains don't actually need to be unloaded.
|
||||
if ( ! $reloadable ) {
|
||||
WP_Translation_Controller::instance()->unload_textdomain( $domain );
|
||||
WP_Translation_Controller::get_instance()->unload_textdomain( $domain );
|
||||
}
|
||||
|
||||
if ( isset( $l10n[ $domain ] ) ) {
|
||||
|
@ -42,20 +42,28 @@ final class WP_Translation_Controller {
|
||||
protected $loaded_files = array();
|
||||
|
||||
/**
|
||||
* Returns the WP_Translation_Controller singleton.
|
||||
* Container for the main instance of the class.
|
||||
*
|
||||
* @since 6.5.0
|
||||
* @var WP_Translation_Controller|null
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Utility method to retrieve the main instance of the class.
|
||||
*
|
||||
* The instance will be created if it does not exist yet.
|
||||
*
|
||||
* @since 6.5.0
|
||||
*
|
||||
* @return WP_Translation_Controller
|
||||
*/
|
||||
public static function instance(): WP_Translation_Controller {
|
||||
static $instance;
|
||||
|
||||
if ( ! $instance ) {
|
||||
$instance = new self();
|
||||
public static function get_instance(): WP_Translation_Controller {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return $instance;
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -622,7 +622,7 @@ $GLOBALS['wp_locale'] = new WP_Locale();
|
||||
$GLOBALS['wp_locale_switcher'] = new WP_Locale_Switcher();
|
||||
$GLOBALS['wp_locale_switcher']->init();
|
||||
|
||||
WP_Translation_Controller::instance()->set_locale( $locale );
|
||||
WP_Translation_Controller::get_instance()->set_locale( $locale );
|
||||
|
||||
// Load the functions for the active theme, for both parent and child theme if applicable.
|
||||
foreach ( wp_get_active_and_valid_themes() as $theme ) {
|
||||
|
@ -30,9 +30,9 @@ class WP_Translation_Controller_Tests extends WP_UnitTestCase {
|
||||
|
||||
$compat_instance = $l10n['wp-tests-domain'] ?? null;
|
||||
|
||||
$is_loaded = WP_Translation_Controller::instance()->is_textdomain_loaded( 'wp-tests-domain' );
|
||||
$headers = WP_Translation_Controller::instance()->get_headers( 'wp-tests-domain' );
|
||||
$entries = WP_Translation_Controller::instance()->get_entries( 'wp-tests-domain' );
|
||||
$is_loaded = WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'wp-tests-domain' );
|
||||
$headers = WP_Translation_Controller::get_instance()->get_headers( 'wp-tests-domain' );
|
||||
$entries = WP_Translation_Controller::get_instance()->get_entries( 'wp-tests-domain' );
|
||||
|
||||
$unload_successful = unload_textdomain( 'wp-tests-domain' );
|
||||
|
||||
@ -76,7 +76,7 @@ class WP_Translation_Controller_Tests extends WP_UnitTestCase {
|
||||
|
||||
$is_loaded_wp = is_textdomain_loaded( 'wp-tests-domain' );
|
||||
|
||||
$is_loaded = WP_Translation_Controller::instance()->is_textdomain_loaded( 'wp-tests-domain' );
|
||||
$is_loaded = WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'wp-tests-domain' );
|
||||
|
||||
remove_filter( 'override_load_textdomain', '__return_true' );
|
||||
|
||||
@ -102,7 +102,7 @@ class WP_Translation_Controller_Tests extends WP_UnitTestCase {
|
||||
public function test_load_textdomain_prefers_php_files_by_default() {
|
||||
$load_successful = load_textdomain( 'wp-tests-domain', DIR_TESTDATA . '/pomo/simple.mo' );
|
||||
|
||||
$instance = WP_Translation_Controller::instance();
|
||||
$instance = WP_Translation_Controller::get_instance();
|
||||
|
||||
$is_loaded = $instance->is_textdomain_loaded( 'wp-tests-domain', 'en_US' );
|
||||
|
||||
@ -259,9 +259,9 @@ class WP_Translation_Controller_Tests extends WP_UnitTestCase {
|
||||
|
||||
$compat_instance = $l10n['wp-tests-domain'] ?? null;
|
||||
|
||||
$is_loaded = WP_Translation_Controller::instance()->is_textdomain_loaded( 'wp-tests-domain' );
|
||||
$headers = WP_Translation_Controller::instance()->get_headers( 'wp-tests-domain' );
|
||||
$entries = WP_Translation_Controller::instance()->get_entries( 'wp-tests-domain' );
|
||||
$is_loaded = WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'wp-tests-domain' );
|
||||
$headers = WP_Translation_Controller::get_instance()->get_headers( 'wp-tests-domain' );
|
||||
$entries = WP_Translation_Controller::get_instance()->get_entries( 'wp-tests-domain' );
|
||||
|
||||
$this->assertNull( $compat_instance, 'Compat instance was not removed' );
|
||||
$this->assertTrue( $unload_successful, 'Text domain not successfully unloaded' );
|
||||
@ -281,13 +281,13 @@ class WP_Translation_Controller_Tests extends WP_UnitTestCase {
|
||||
|
||||
$unload_successful = unload_textdomain( 'wp-tests-domain' );
|
||||
|
||||
$is_loaded = WP_Translation_Controller::instance()->is_textdomain_loaded( 'wp-tests-domain' );
|
||||
$is_loaded = WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'wp-tests-domain' );
|
||||
|
||||
remove_filter( 'override_unload_textdomain', '__return_true' );
|
||||
|
||||
$unload_successful_after = unload_textdomain( 'wp-tests-domain' );
|
||||
|
||||
$is_loaded_after = WP_Translation_Controller::instance()->is_textdomain_loaded( 'wp-tests-domain' );
|
||||
$is_loaded_after = WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'wp-tests-domain' );
|
||||
|
||||
$this->assertTrue( $unload_successful );
|
||||
$this->assertTrue( $is_loaded );
|
||||
@ -317,14 +317,14 @@ class WP_Translation_Controller_Tests extends WP_UnitTestCase {
|
||||
|
||||
$actual = __( 'Invalid parameter.' );
|
||||
|
||||
$this->assertTrue( WP_Translation_Controller::instance()->is_textdomain_loaded() );
|
||||
$this->assertTrue( WP_Translation_Controller::instance()->is_textdomain_loaded( 'default', 'es_ES' ) );
|
||||
$this->assertTrue( WP_Translation_Controller::get_instance()->is_textdomain_loaded() );
|
||||
$this->assertTrue( WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'default', 'es_ES' ) );
|
||||
|
||||
restore_previous_locale();
|
||||
|
||||
$actual_2 = __( 'Invalid parameter.' );
|
||||
|
||||
$this->assertTrue( WP_Translation_Controller::instance()->is_textdomain_loaded( 'default', 'es_ES' ) );
|
||||
$this->assertTrue( WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'default', 'es_ES' ) );
|
||||
|
||||
$this->assertSame( 'Parámetro no válido. ', $actual );
|
||||
$this->assertSame( 'Invalid parameter.', $actual_2 );
|
||||
@ -336,7 +336,7 @@ class WP_Translation_Controller_Tests extends WP_UnitTestCase {
|
||||
* @covers ::change_locale
|
||||
*/
|
||||
public function test_switch_to_locale_translations_stay_loaded_custom_textdomain() {
|
||||
$this->assertSame( 'en_US', WP_Translation_Controller::instance()->get_locale() );
|
||||
$this->assertSame( 'en_US', WP_Translation_Controller::get_instance()->get_locale() );
|
||||
|
||||
require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php';
|
||||
|
||||
@ -346,16 +346,16 @@ class WP_Translation_Controller_Tests extends WP_UnitTestCase {
|
||||
|
||||
$actual = i18n_plugin_test();
|
||||
|
||||
$this->assertSame( 'es_ES', WP_Translation_Controller::instance()->get_locale() );
|
||||
$this->assertTrue( WP_Translation_Controller::instance()->is_textdomain_loaded( 'internationalized-plugin', 'es_ES' ) );
|
||||
$this->assertTrue( WP_Translation_Controller::instance()->is_textdomain_loaded( 'default', 'es_ES' ) );
|
||||
$this->assertFalse( WP_Translation_Controller::instance()->is_textdomain_loaded( 'foo-bar', 'es_ES' ) );
|
||||
$this->assertSame( 'es_ES', WP_Translation_Controller::get_instance()->get_locale() );
|
||||
$this->assertTrue( WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'internationalized-plugin', 'es_ES' ) );
|
||||
$this->assertTrue( WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'default', 'es_ES' ) );
|
||||
$this->assertFalse( WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'foo-bar', 'es_ES' ) );
|
||||
|
||||
restore_previous_locale();
|
||||
|
||||
$after = i18n_plugin_test();
|
||||
|
||||
$this->assertTrue( WP_Translation_Controller::instance()->is_textdomain_loaded( 'internationalized-plugin', 'es_ES' ) );
|
||||
$this->assertTrue( WP_Translation_Controller::get_instance()->is_textdomain_loaded( 'internationalized-plugin', 'es_ES' ) );
|
||||
|
||||
$this->assertSame( 'This is a dummy plugin', $before );
|
||||
$this->assertSame( 'Este es un plugin dummy', $actual );
|
||||
|
@ -10,8 +10,8 @@ class WP_Translation_Controller_Convert_Tests extends WP_UnitTestCase {
|
||||
* @covers ::instance
|
||||
*/
|
||||
public function test_get_instance() {
|
||||
$instance = WP_Translation_Controller::instance();
|
||||
$instance2 = WP_Translation_Controller::instance();
|
||||
$instance = WP_Translation_Controller::get_instance();
|
||||
$instance2 = WP_Translation_Controller::get_instance();
|
||||
|
||||
$this->assertSame( $instance, $instance2 );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user