diff --git a/src/SlmLocale/Strategy/HttpAcceptLanguageStrategy.php b/src/SlmLocale/Strategy/HttpAcceptLanguageStrategy.php index fd6a2fa..b728c5b 100644 --- a/src/SlmLocale/Strategy/HttpAcceptLanguageStrategy.php +++ b/src/SlmLocale/Strategy/HttpAcceptLanguageStrategy.php @@ -67,10 +67,10 @@ public function detect(LocaleEvent $event) return $locale; } - if (Locale::lookup($supported, $locale)) { - return $locale; + if ($match = Locale::lookup($supported, $locale)) { + return $match; } } } } -} \ No newline at end of file +} diff --git a/tests/SlmLocaleTest/Strategy/HttpAcceptLanguageStrategyTest.php b/tests/SlmLocaleTest/Strategy/HttpAcceptLanguageStrategyTest.php index b704303..d2ea4a5 100644 --- a/tests/SlmLocaleTest/Strategy/HttpAcceptLanguageStrategyTest.php +++ b/tests/SlmLocaleTest/Strategy/HttpAcceptLanguageStrategyTest.php @@ -121,4 +121,24 @@ public function testSelectsOnlyLanguageFromSupportedList() $locale = $strategy->detect($event); $this->assertEquals('bar', $locale); } + + public function testSelectsLanguageViaLocaleLookup() + { + $strategy = $this->strategy; + $event = $this->event; + + $header = new AcceptLanguage; + $header->addLanguage('de-DE', 1); + $header->addLanguage('en-US', 0.8); + $header->addLanguage('en', 0.6); + + $event->getRequest() + ->getHeaders() + ->addHeader($header); + + $event->setSupported(array('en', 'de')); + + $locale = $strategy->detect($event); + $this->assertEquals('de', $locale); + } }