Browse Source

Update usage of I18n::locale()

Don't use the deprecated method.
Mark Story 8 years ago
parent
commit
0212f72ae6

+ 1 - 1
src/I18n/Middleware/LocaleSelectorMiddleware.php

@@ -56,7 +56,7 @@ class LocaleSelectorMiddleware
             return $next($request, $response);
         }
         if (in_array($locale, $this->locales) || $this->locales === ['*']) {
-            I18n::locale($locale);
+            I18n::setLocale($locale);
         }
 
         return $next($request, $response);

+ 2 - 2
src/I18n/README.md

@@ -20,7 +20,7 @@ should you wish to create them manually instead of using the conventions this li
 ```php
 use Cake\I18n\I18n;
 
-I18n::locale('en_US');
+I18n::setLocale('en_US');
 ```
 
 ### Setting path to folder containing po files.
@@ -66,7 +66,7 @@ I18n::translator('animals', 'fr_FR', function () {
     return $package;
 });
 
-I18n::locale('fr_FR');
+I18n::getLocale('fr_FR');
 __d('animals', 'Dog'); // Returns "Chien"
 ```
 

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

@@ -417,7 +417,7 @@ class TranslateBehavior extends Behavior implements PropertyMarshalInterface
     public function locale($locale = null)
     {
         if ($locale === null) {
-            return $this->_locale ?: I18n::locale();
+            return $this->_locale ?: I18n::getLocale();
         }
 
         return $this->_locale = (string)$locale;

+ 1 - 1
src/Routing/Filter/LocaleSelectorFilter.php

@@ -66,6 +66,6 @@ class LocaleSelectorFilter extends DispatcherFilter
             return;
         }
 
-        I18n::locale($locale);
+        I18n::setLocale($locale);
     }
 }

+ 6 - 6
tests/TestCase/Database/Type/DecimalTypeTest.php

@@ -55,10 +55,10 @@ class DecimalTypeTest extends TestCase
         parent::setUp();
         $this->type = Type::build('decimal');
         $this->driver = $this->getMockBuilder('Cake\Database\Driver')->getMock();
-        $this->localeString = I18n::locale();
+        $this->localeString = I18n::getLocale();
         $this->numberClass = DecimalType::$numberClass;
 
-        I18n::locale($this->localeString);
+        I18n::setLocale($this->localeString);
     }
 
     /**
@@ -69,7 +69,7 @@ class DecimalTypeTest extends TestCase
     public function tearDown()
     {
         parent::tearDown();
-        I18n::locale($this->localeString);
+        I18n::setLocale($this->localeString);
         DecimalType::$numberClass = $this->numberClass;
     }
 
@@ -162,19 +162,19 @@ class DecimalTypeTest extends TestCase
      */
     public function testMarshalWithLocaleParsing()
     {
-        I18n::locale('de_DE');
+        I18n::setLocale('de_DE');
         $this->type->useLocaleParser();
         $expected = 1234.53;
         $result = $this->type->marshal('1.234,53');
         $this->assertEquals($expected, $result);
 
-        I18n::locale('en_US');
+        I18n::setLocale('en_US');
         $this->type->useLocaleParser();
         $expected = 1234;
         $result = $this->type->marshal('1,234');
         $this->assertEquals($expected, $result);
 
-        I18n::locale('pt_BR');
+        I18n::setLocale('pt_BR');
         $this->type->useLocaleParser();
         $expected = 5987123.231;
         $result = $this->type->marshal('5.987.123,231');

+ 6 - 6
tests/TestCase/Database/Type/FloatTypeTest.php

@@ -55,10 +55,10 @@ class FloatTypeTest extends TestCase
         parent::setUp();
         $this->type = Type::build('float');
         $this->driver = $this->getMockBuilder('Cake\Database\Driver')->getMock();
-        $this->localeString = I18n::locale();
+        $this->localeString = I18n::getLocale();
         $this->numberClass = FloatType::$numberClass;
 
-        I18n::locale($this->localeString);
+        I18n::setLocale($this->localeString);
     }
 
     /**
@@ -69,7 +69,7 @@ class FloatTypeTest extends TestCase
     public function tearDown()
     {
         parent::tearDown();
-        I18n::locale($this->localeString);
+        I18n::setLocale($this->localeString);
         FloatType::$numberClass = $this->numberClass;
     }
 
@@ -151,19 +151,19 @@ class FloatTypeTest extends TestCase
      */
     public function testMarshalWithLocaleParsing()
     {
-        I18n::locale('de_DE');
+        I18n::setLocale('de_DE');
         $this->type->useLocaleParser();
         $expected = 1234.53;
         $result = $this->type->marshal('1.234,53');
         $this->assertEquals($expected, $result);
 
-        I18n::locale('en_US');
+        I18n::setLocale('en_US');
         $this->type->useLocaleParser();
         $expected = 1234;
         $result = $this->type->marshal('1,234');
         $this->assertEquals($expected, $result);
 
-        I18n::locale('pt_BR');
+        I18n::setLocale('pt_BR');
         $this->type->useLocaleParser();
         $expected = 5987123.231;
         $result = $this->type->marshal('5.987.123,231');

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

@@ -41,7 +41,7 @@ class I18nTest extends TestCase
     public function setUp()
     {
         parent::setUp();
-        $this->locale = I18n::locale();
+        $this->locale = I18n::getLocale();
     }
 
     /**
@@ -54,7 +54,7 @@ class I18nTest extends TestCase
         parent::tearDown();
         I18n::clear();
         I18n::defaultFormatter('default');
-        I18n::locale($this->locale);
+        I18n::setLocale($this->locale);
         Plugin::unload();
         Cache::clear(false, '_cake_core_');
     }
@@ -202,12 +202,12 @@ class I18nTest extends TestCase
      *
      * @return void
      */
-    public function testDefaultLocale()
+    public function testGetDefaultLocale()
     {
-        $this->assertEquals('en_US', I18n::locale());
+        $this->assertEquals('en_US', I18n::getLocale());
         $this->assertEquals('en_US', ini_get('intl.default_locale'));
-        I18n::locale('fr_FR');
-        $this->assertEquals('fr_FR', I18n::locale());
+        I18n::setLocale('fr_FR');
+        $this->assertEquals('fr_FR', I18n::getLocale());
         $this->assertEquals('fr_FR', ini_get('intl.default_locale'));
     }
 
@@ -228,7 +228,7 @@ class I18nTest extends TestCase
             return $package;
         }, 'fr_FR');
 
-        I18n::locale('fr_FR');
+        I18n::setLocale('fr_FR');
         $translator = I18n::getTranslator('custom');
         $this->assertEquals('Le moo', $translator->translate('Cow'));
     }

+ 6 - 6
tests/TestCase/I18n/Middleware/LocaleSelectorMiddlewareTest.php

@@ -64,13 +64,13 @@ class LocaleSelectorMiddlewareTest extends TestCase
         $response = new Response();
         $middleware = new LocaleSelectorMiddleware([]);
         $middleware($request, $response, $this->next);
-        $this->assertSame($this->locale, I18n::locale());
+        $this->assertSame($this->locale, I18n::getLocale());
 
         $request = ServerRequestFactory::fromGlobals(['HTTP_ACCEPT_LANGUAGE' => 'garbage']);
         $response = new Response();
         $middleware = new LocaleSelectorMiddleware([]);
         $middleware($request, $response, $this->next);
-        $this->assertSame($this->locale, I18n::locale());
+        $this->assertSame($this->locale, I18n::getLocale());
     }
 
     /**
@@ -84,7 +84,7 @@ class LocaleSelectorMiddlewareTest extends TestCase
         $response = new Response();
         $middleware = new LocaleSelectorMiddleware(['en_CA', 'en_US', 'es']);
         $middleware($request, $response, $this->next);
-        $this->assertSame($this->locale, I18n::locale(), 'en-GB is not accepted');
+        $this->assertSame($this->locale, I18n::getLocale(), 'en-GB is not accepted');
     }
 
     /**
@@ -98,7 +98,7 @@ class LocaleSelectorMiddlewareTest extends TestCase
         $response = new Response();
         $middleware = new LocaleSelectorMiddleware(['en_CA', 'es']);
         $middleware($request, $response, $this->next);
-        $this->assertSame('es', I18n::locale(), 'es is accepted');
+        $this->assertSame('es', I18n::getLocale(), 'es is accepted');
     }
 
     /**
@@ -113,10 +113,10 @@ class LocaleSelectorMiddlewareTest extends TestCase
 
         $request = ServerRequestFactory::fromGlobals(['HTTP_ACCEPT_LANGUAGE' => 'es,es-ES;q=0.8,da;q=0.4']);
         $middleware($request, $response, $this->next);
-        $this->assertSame('es', I18n::locale(), 'es is accepted');
+        $this->assertSame('es', I18n::getLocale(), 'es is accepted');
 
         $request = ServerRequestFactory::fromGlobals(['HTTP_ACCEPT_LANGUAGE' => 'en;q=0.4,es;q=0.6,da;q=0.8']);
         $middleware($request, $response, $this->next);
-        $this->assertSame('da', I18n::locale(), 'da is accepted');
+        $this->assertSame('da', I18n::getLocale(), 'da is accepted');
     }
 }

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

@@ -35,7 +35,7 @@ class NumberTest extends TestCase
     {
         parent::setUp();
         $this->Number = new Number();
-        $this->locale = I18n::locale();
+        $this->locale = I18n::getLocale();
     }
 
     /**
@@ -47,7 +47,7 @@ class NumberTest extends TestCase
     {
         parent::tearDown();
         unset($this->Number);
-        I18n::locale($this->locale);
+        I18n::setLocale($this->locale);
         Number::defaultCurrency(false);
     }
 
@@ -100,13 +100,13 @@ class NumberTest extends TestCase
      */
     public function testParseFloat()
     {
-        I18n::locale('de_DE');
+        I18n::setLocale('de_DE');
         $value = '1.234.567,891';
         $result = $this->Number->parseFloat($value);
         $expected = 1234567.891;
         $this->assertEquals($expected, $result);
 
-        I18n::locale('pt_BR');
+        I18n::setLocale('pt_BR');
         $value = '1.234,37';
         $result = $this->Number->parseFloat($value);
         $expected = 1234.37;
@@ -308,7 +308,7 @@ class NumberTest extends TestCase
         $this->assertEquals('USD', $result);
 
         $this->Number->defaultCurrency(false);
-        I18n::locale('es_ES');
+        I18n::setLocale('es_ES');
         $this->assertEquals('EUR', $this->Number->defaultCurrency());
 
         $this->Number->defaultCurrency('JPY');
@@ -398,7 +398,7 @@ class NumberTest extends TestCase
      */
     public function testPrecisionLocalized()
     {
-        I18n::locale('fr_FR');
+        I18n::setLocale('fr_FR');
         $result = $this->Number->precision(1.234);
         $this->assertEquals('1,234', $result);
     }
@@ -530,7 +530,7 @@ class NumberTest extends TestCase
      */
     public function testReadableSizeLocalized()
     {
-        I18n::locale('fr_FR');
+        I18n::setLocale('fr_FR');
         $result = $this->Number->toReadableSize(1321205);
         $this->assertEquals('1,26 MB', $result);
 
@@ -563,7 +563,7 @@ class NumberTest extends TestCase
      */
     public function testOrdinal()
     {
-        I18n::locale('en_US');
+        I18n::setLocale('en_US');
         $result = $this->Number->ordinal(1);
         $this->assertEquals('1st', $result);
 
@@ -581,7 +581,7 @@ class NumberTest extends TestCase
         $result = $this->Number->ordinal(4);
         $this->assertEquals('4th', $result);
 
-        I18n::locale('fr_FR');
+        I18n::setLocale('fr_FR');
         $result = $this->Number->ordinal(1);
         $this->assertEquals('1er', $result);
 

+ 2 - 2
tests/TestCase/I18n/TimeTest.php

@@ -58,7 +58,7 @@ class TimeTest extends TestCase
         FrozenTime::setJsonEncodeFormat("yyyy-MM-dd'T'HH:mm:ssxxx");
 
         date_default_timezone_set('UTC');
-        I18n::locale(I18n::DEFAULT_LOCALE);
+        I18n::setLocale(I18n::DEFAULT_LOCALE);
     }
 
     /**
@@ -845,7 +845,7 @@ class TimeTest extends TestCase
      */
     public function testRussianTimeAgoInWords($class)
     {
-        I18n::locale('ru_RU');
+        I18n::setLocale('ru_RU');
         $time = new $class('5 days ago');
         $result = $time->timeAgoInWords();
         $this->assertEquals('5 days ago', $result);

+ 9 - 9
tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php

@@ -55,7 +55,7 @@ class TranslateBehaviorTest extends TestCase
     public function tearDown()
     {
         parent::tearDown();
-        I18n::locale(I18n::defaultLocale());
+        I18n::setLocale(I18n::defaultLocale());
         TableRegistry::clear();
     }
 
@@ -179,7 +179,7 @@ class TranslateBehaviorTest extends TestCase
      */
     public function testFindSingleLocaleAssociatedEnv()
     {
-        I18n::locale('eng');
+        I18n::setLocale('eng');
 
         $table = TableRegistry::get('Articles');
         $table->addBehavior('Translate', ['fields' => ['title', 'body']]);
@@ -226,7 +226,7 @@ class TranslateBehaviorTest extends TestCase
         ];
         $this->assertSame($expected, $results);
 
-        I18n::locale('spa');
+        I18n::setLocale('spa');
 
         $results = $table->find()
             ->select(['id', 'title', 'body'])
@@ -339,11 +339,11 @@ class TranslateBehaviorTest extends TestCase
         $field = $table->translationField('title');
         $this->assertSame($expectedSameLocale, $field);
 
-        I18n::locale('es_ES');
+        I18n::setLocale('es_ES');
         $field = $table->translationField('title');
         $this->assertSame($expectedOtherLocale, $field);
 
-        I18n::locale('en');
+        I18n::setLocale('en');
         $field = $table->translationField('title');
         $this->assertSame($expectedOtherLocale, $field);
 
@@ -354,11 +354,11 @@ class TranslateBehaviorTest extends TestCase
             'defaultLocale' => 'de_DE'
         ]);
 
-        I18n::locale('de_DE');
+        I18n::setLocale('de_DE');
         $field = $table->translationField('title');
         $this->assertSame($expectedSameLocale, $field);
 
-        I18n::locale('en_US');
+        I18n::setLocale('en_US');
         $field = $table->translationField('title');
         $this->assertSame($expectedOtherLocale, $field);
 
@@ -1112,7 +1112,7 @@ class TranslateBehaviorTest extends TestCase
         $table = TableRegistry::get('Articles');
         $table->addBehavior('Translate', ['fields' => ['title', 'body']]);
         $table->entityClass(__NAMESPACE__ . '\Article');
-        I18n::locale('fra');
+        I18n::setLocale('fra');
         $translations = [
             'fra' => ['title' => 'Un article'],
             'spa' => ['title' => 'Un artículo']
@@ -1290,7 +1290,7 @@ class TranslateBehaviorTest extends TestCase
         $table = TableRegistry::get('Articles');
         $table->addBehavior('Translate', ['fields' => ['title']]);
         $table->entityClass(__NAMESPACE__ . '\Article');
-        I18n::locale('fra');
+        I18n::setLocale('fra');
         $article = $table->get(1);
         $article->set('body', 'New Body');
         $table->save($article);

+ 5 - 5
tests/TestCase/Routing/Filter/LocaleSelectorFilterTest.php

@@ -64,19 +64,19 @@ class LocaleSelectorFilterTest extends TestCase
             'environment' => ['HTTP_ACCEPT_LANGUAGE' => 'en-GB,en;q=0.8,es;q=0.6,da;q=0.4']
         ]);
         $filter->beforeDispatch(new Event('name', null, ['request' => $request]));
-        $this->assertEquals('en_GB', I18n::locale());
+        $this->assertEquals('en_GB', I18n::getLocale());
 
         $request = new ServerRequest([
             'environment' => ['HTTP_ACCEPT_LANGUAGE' => 'es_VE,en;q=0.8,es;q=0.6,da;q=0.4']
         ]);
         $filter->beforeDispatch(new Event('name', null, ['request' => $request]));
-        $this->assertEquals('es_VE', I18n::locale());
+        $this->assertEquals('es_VE', I18n::getLocale());
 
         $request = new ServerRequest([
             'environment' => ['HTTP_ACCEPT_LANGUAGE' => 'en;q=0.4,es;q=0.6,da;q=0.8']
         ]);
         $filter->beforeDispatch(new Event('name', null, ['request' => $request]));
-        $this->assertEquals('da', I18n::locale());
+        $this->assertEquals('da', I18n::getLocale());
     }
 
     /**
@@ -98,7 +98,7 @@ class LocaleSelectorFilterTest extends TestCase
             ]
         ]);
         $filter->beforeDispatch(new Event('name', null, ['request' => $request]));
-        $this->assertEquals('es_VE', I18n::locale());
+        $this->assertEquals('es_VE', I18n::getLocale());
 
         Locale::setDefault('en_US');
         $request = new ServerRequest([
@@ -107,6 +107,6 @@ class LocaleSelectorFilterTest extends TestCase
             ]
         ]);
         $filter->beforeDispatch(new Event('name', null, ['request' => $request]));
-        $this->assertEquals('en_US', I18n::locale());
+        $this->assertEquals('en_US', I18n::getLocale());
     }
 }

+ 5 - 5
tests/TestCase/Validation/ValidationTest.php

@@ -1588,13 +1588,13 @@ class ValidationTest extends TestCase
      */
     public function testLocalizedTime()
     {
-        $locale = I18N::locale();
+        $locale = I18N::getLocale();
 
         $this->assertFalse(Validation::localizedTime('', 'date'));
         $this->assertFalse(Validation::localizedTime('invalid', 'date'));
 
         // English (US)
-        I18N::locale('en_US');
+        I18N::setLocale('en_US');
         $this->assertTrue(Validation::localizedTime('12/31/2006', 'date'));
         $this->assertTrue(Validation::localizedTime('6.40pm', 'time'));
         $this->assertTrue(Validation::localizedTime('12/31/2006 6.40pm', 'datetime'));
@@ -1604,7 +1604,7 @@ class ValidationTest extends TestCase
         $this->assertFalse(Validation::localizedTime('18:40', 'time')); // non-US format
 
         // German
-        I18N::locale('de_DE');
+        I18N::setLocale('de_DE');
         $this->assertTrue(Validation::localizedTime('31.12.2006', 'date'));
         $this->assertTrue(Validation::localizedTime('31. Dezember 2006', 'date'));
         $this->assertTrue(Validation::localizedTime('18:40', 'time'));
@@ -1612,12 +1612,12 @@ class ValidationTest extends TestCase
         $this->assertFalse(Validation::localizedTime('December 31, 2006', 'date')); // non-German format
 
         // Russian
-        I18N::locale('ru_RU');
+        I18N::setLocale('ru_RU');
         $this->assertTrue(Validation::localizedTime('31 декабря 2006', 'date'));
 
         $this->assertFalse(Validation::localizedTime('December 31, 2006', 'date')); // non-Russian format
 
-        I18N::locale($locale);
+        I18N::setLocale($locale);
     }
 
     /**

+ 3 - 3
tests/TestCase/View/Helper/PaginatorHelperTest.php

@@ -75,7 +75,7 @@ class PaginatorHelperTest extends TestCase
         Router::connect('/:controller/:action/*');
         Router::connect('/:plugin/:controller/:action/*');
 
-        $this->locale = I18n::locale();
+        $this->locale = I18n::getLocale();
     }
 
     /**
@@ -88,7 +88,7 @@ class PaginatorHelperTest extends TestCase
         parent::tearDown();
         unset($this->View, $this->Paginator);
 
-        I18n::locale($this->locale);
+        I18n::setLocale($this->locale);
     }
 
     /**
@@ -2616,7 +2616,7 @@ class PaginatorHelperTest extends TestCase
         $result = $this->Paginator->counter($input);
         $this->assertEquals($expected, $result);
 
-        I18n::locale('de-DE');
+        I18n::setLocale('de-DE');
         $expected = 'Page 1.523 of 1.000, showing 1.230 records out of 234.567 total, ';
         $expected .= 'starting on record 4.566.001, ending on 234.567';
         $result = $this->Paginator->counter($input);

+ 3 - 3
tests/TestCase/View/Helper/TimeHelperTest.php

@@ -47,7 +47,7 @@ class TimeHelperTest extends TestCase
         $this->View = new View();
         $this->Time = new TimeHelper($this->View);
         Time::$defaultLocale = 'en_US';
-        $this->locale = I18n::locale();
+        $this->locale = I18n::getLocale();
     }
 
     /**
@@ -59,7 +59,7 @@ class TimeHelperTest extends TestCase
     {
         parent::tearDown();
         Time::$defaultLocale = 'en_US';
-        I18n::locale($this->locale);
+        I18n::setLocale($this->locale);
     }
 
     /**
@@ -522,7 +522,7 @@ class TimeHelperTest extends TestCase
         $expected = 'Date invalid';
         $this->assertEquals($expected, $result);
 
-        I18n::locale('fr_FR');
+        I18n::setLocale('fr_FR');
         Time::$defaultLocale = 'fr_FR';
         $time = new \Cake\I18n\FrozenTime('Thu Jan 14 13:59:28 2010');
         $result = $this->Time->format($time, \IntlDateFormatter::FULL);