Skip to content

Commit

Permalink
Merge pull request #69 from swiftchase/master
Browse files Browse the repository at this point in the history
Improved locale lookup via Accept-Language strategy
  • Loading branch information
Jurian Sluiman committed Aug 19, 2015
2 parents 986835b + 392ec42 commit 7837559
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/SlmLocale/Strategy/HttpAcceptLanguageStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
}
}
20 changes: 20 additions & 0 deletions tests/SlmLocaleTest/Strategy/HttpAcceptLanguageStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 7837559

Please sign in to comment.