Browse Source

rename I18n::defaultLocale to I18n::locale

there's only ever one locale in play
AD7six 11 years ago
parent
commit
78e6420b79

+ 5 - 5
src/I18n/I18n.php

@@ -66,13 +66,13 @@ class I18n {
 				},
 			]),
 			new TranslatorFactory,
-			static::defaultLocale()
+			static::locale()
 		);
 	}
 
 /**
  * Returns an instance of a translator that was configured for the name and passed
- * locale. If no locale is passed then it takes the value returned by the `defaultLocale()` method.
+ * locale. If no locale is passed then it takes the value returned by the `locale()` method.
  *
  * This method can be used to configure future translators, this is achieved by passing a callable
  * as the last argument of this function.
@@ -113,7 +113,7 @@ class I18n {
 	public static function translator($name = 'default', $locale = null, callable $loader = null) {
 		if ($loader !== null) {
 			$packages = static::translators()->getPackages();
-			$locale = $locale ?: static::defaultLocale();
+			$locale = $locale ?: static::locale();
 
 			if ($name !== 'default') {
 				$loader = function() use ($loader) {
@@ -197,12 +197,12 @@ class I18n {
  * This also affects the `intl.default_locale` PHP setting.
  *
  * When called with no arguments it will return the currently configure
- * defaultLocale as stored in the `intl.default_locale` PHP setting.
+ * locale as stored in the `intl.default_locale` PHP setting.
  *
  * @param string $locale The name of the locale to set as default.
  * @return string|null The name of the default locale.
  */
-	public static function defaultLocale($locale = null) {
+	public static function locale($locale = null) {
 		static::environmentLocale();
 
 		if (!empty($locale)) {

+ 1 - 1
src/Model/Behavior/TranslateBehavior.php

@@ -234,7 +234,7 @@ class TranslateBehavior extends Behavior {
  */
 	public function locale($locale = null) {
 		if ($locale === null) {
-			return $this->_locale ?: I18n::defaultLocale();
+			return $this->_locale ?: I18n::locale();
 		}
 		return $this->_locale = (string)$locale;
 	}

+ 7 - 7
tests/TestCase/I18n/I18nTest.php

@@ -40,7 +40,7 @@ class I18nTest extends TestCase {
  */
 	public function setUp() {
 		parent::setUp();
-		$this->locale = I18n::defaultLocale();
+		$this->locale = I18n::locale();
 	}
 
 /**
@@ -52,7 +52,7 @@ class I18nTest extends TestCase {
 		parent::tearDown();
 		I18n::clear();
 		I18n::defaultFormatter('default');
-		I18n::defaultLocale($this->locale);
+		I18n::locale($this->locale);
 		Plugin::unload();
 		Cache::clear(false, '_cake_core_');
 	}
@@ -169,15 +169,15 @@ class I18nTest extends TestCase {
 	}
 
 /**
- * Tests the defaultLocale method
+ * Tests the locale method
  *
  * @return void
  */
 	public function testDefaultLocale() {
-		$this->assertEquals('en_US', I18n::defaultLocale());
+		$this->assertEquals('en_US', I18n::locale());
 		$this->assertEquals('en_US', ini_get('intl.default_locale'));
-		I18n::defaultLocale('fr_FR');
-		$this->assertEquals('fr_FR', I18n::defaultLocale());
+		I18n::locale('fr_FR');
+		$this->assertEquals('fr_FR', I18n::locale());
 		$this->assertEquals('fr_FR', ini_get('intl.default_locale'));
 	}
 
@@ -196,7 +196,7 @@ class I18nTest extends TestCase {
 			return $package;
 		});
 
-		I18n::defaultLocale('fr_FR');
+		I18n::locale('fr_FR');
 		$translator = I18n::translator('custom');
 		$this->assertEquals('Le moo', $translator->translate('Cow'));
 	}

+ 5 - 5
tests/TestCase/I18n/NumberTest.php

@@ -34,7 +34,7 @@ class NumberTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 		$this->Number = new Number();
-		$this->locale = I18n::defaultLocale();
+		$this->locale = I18n::locale();
 	}
 
 /**
@@ -45,7 +45,7 @@ class NumberTest extends TestCase {
 	public function tearDown() {
 		parent::tearDown();
 		unset($this->Number);
-		I18n::defaultLocale($this->locale);
+		I18n::locale($this->locale);
 		Number::defaultCurrency(false);
 	}
 
@@ -276,7 +276,7 @@ class NumberTest extends TestCase {
 		$this->assertEquals('USD', $result);
 
 		$this->Number->defaultCurrency(false);
-		I18n::defaultLocale('es_ES');
+		I18n::locale('es_ES');
 		$this->assertEquals('EUR', $this->Number->defaultCurrency());
 
 		$this->Number->defaultCurrency('JPY');
@@ -361,7 +361,7 @@ class NumberTest extends TestCase {
  * @return void
  */
 	public function testPrecisionLocalized() {
-		I18n::defaultLocale('fr_FR');
+		I18n::locale('fr_FR');
 		$result = $this->Number->precision(1.234);
 		$this->assertEquals('1,234', $result);
 	}
@@ -486,7 +486,7 @@ class NumberTest extends TestCase {
  * @return void
  */
 	public function testReadableSizeLocalized() {
-		I18n::defaultLocale('fr_FR');
+		I18n::locale('fr_FR');
 		$result = $this->Number->toReadableSize(1321205);
 		$this->assertEquals('1,26 MB', $result);
 

+ 3 - 3
tests/TestCase/Model/Behavior/TranslateBehaviorTest.php

@@ -41,7 +41,7 @@ class TranslateBehaviorTest extends TestCase {
 
 	public function tearDown() {
 		parent::tearDown();
-		I18n::defaultLocale(I18n::environmentLocale());
+		I18n::locale(I18n::environmentLocale());
 		TableRegistry::clear();
 	}
 
@@ -88,7 +88,7 @@ class TranslateBehaviorTest extends TestCase {
  * @return void
  */
 	public function testFindSingleLocaleAssociatedEnv() {
-		I18n::defaultLocale('eng');
+		I18n::locale('eng');
 
 		$table = TableRegistry::get('Articles');
 		$table->addBehavior('Translate', ['fields' => ['title', 'body']]);
@@ -135,7 +135,7 @@ class TranslateBehaviorTest extends TestCase {
 		];
 		$this->assertSame($expected, $results);
 
-		I18n::defaultLocale('spa');
+		I18n::locale('spa');
 
 		$results = $table->find()
 			->select(['id', 'title', 'body'])