Skip to content
Permalink
Browse files

Use Locale::lookup to handle generic options as a fallback

  • Loading branch information...
Zuluru committed Oct 20, 2018
1 parent e653392 commit afa1fe9dd5f9fff5762f481c85b7f0eeec57b8e7
@@ -55,7 +55,10 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
if (!$locale) {
return $next($request, $response);
}
if (in_array($locale, $this->locales) || $this->locales === ['*']) {
if ($this->locales !== ['*']) {
$locale = Locale::lookup($this->locales, $locale, true);
}
if ($locale || $this->locales === ['*']) {
I18n::setLocale($locale);
}
@@ -101,6 +101,20 @@ public function testInvokeLocaleAccepted()
$this->assertSame('es', I18n::getLocale(), 'es is accepted');
}
/**
* The default locale should change when the request locale has an accepted fallback option
*
* @return void
*/
public function testInvokeLocaleAcceptedFallback()
{
$request = ServerRequestFactory::fromGlobals(['HTTP_ACCEPT_LANGUAGE' => 'es-ES;q=0.8,da;q=0.4']);
$response = new Response();
$middleware = new LocaleSelectorMiddleware(['en_CA', 'es']);
$middleware($request, $response, $this->next);
$this->assertSame('es', I18n::getLocale(), 'es is accepted');
}
/**
* The default locale should change when the '*' is accepted
*

0 comments on commit afa1fe9

Please sign in to comment.
You can’t perform that action at this time.