diff --git a/src/Routing/Filter/LocaleSelectorFilter.php b/src/Routing/Filter/LocaleSelectorFilter.php index bb6d54ad2e0..31e7ae3a48d 100644 --- a/src/Routing/Filter/LocaleSelectorFilter.php +++ b/src/Routing/Filter/LocaleSelectorFilter.php @@ -17,6 +17,7 @@ use Cake\Event\Event; use Cake\Routing\DispatcherFilter; use Locale; +use Cake\I18n\I18n; /** * Sets the runtime default locale for the request based on the @@ -48,7 +49,7 @@ public function __construct($config = []) } /** - * Inspects the request for the Accept-Language header and sets the default + * Inspects the request for the Accept-Language header and sets the * Locale for the current runtime if it matches the list of valid locales * as passed in the configuration. * @@ -64,6 +65,6 @@ public function beforeDispatch(Event $event) return; } - Locale::setDefault($locale); + I18n::locale($locale); } } diff --git a/tests/TestCase/Routing/Filter/LocaleSelectorFilterTest.php b/tests/TestCase/Routing/Filter/LocaleSelectorFilterTest.php index 4dbd9495387..148a265a273 100644 --- a/tests/TestCase/Routing/Filter/LocaleSelectorFilterTest.php +++ b/tests/TestCase/Routing/Filter/LocaleSelectorFilterTest.php @@ -19,6 +19,7 @@ use Cake\Routing\Filter\LocaleSelectorFilter; use Cake\TestSuite\TestCase; use Locale; +use Cake\I18n\I18n; /** * Locale selector filter test. @@ -63,19 +64,19 @@ public function testSimpleSelection() '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', Locale::getDefault()); + $this->assertEquals('en_GB', I18n::locale()); $request = new Request([ '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', Locale::getDefault()); + $this->assertEquals('es_VE', I18n::locale()); $request = new Request([ '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', Locale::getDefault()); + $this->assertEquals('da', I18n::locale()); } /** @@ -97,7 +98,7 @@ public function testWithWhitelist() ] ]); $filter->beforeDispatch(new Event('name', null, ['request' => $request])); - $this->assertEquals('es_VE', Locale::getDefault()); + $this->assertEquals('es_VE', I18n::locale()); Locale::setDefault('en_US'); $request = new Request([ @@ -106,6 +107,6 @@ public function testWithWhitelist() ] ]); $filter->beforeDispatch(new Event('name', null, ['request' => $request])); - $this->assertEquals('en_US', Locale::getDefault()); + $this->assertEquals('en_US', I18n::locale()); } }