public detectLocaleFromLocaleTag ( string $localeIdentifier ) : |
||
$localeIdentifier | string | The locale identifier as used in Locale class |
리턴 | Best-matching existing Locale instance |
public function detectLocaleFromLocaleTag($localeIdentifier)
{
try {
return $this->detectLocaleFromTemplateLocale(new Locale($localeIdentifier));
} catch (Exception\InvalidLocaleIdentifierException $exception) {
return $this->localizationService->getConfiguration()->getDefaultLocale();
}
}
/** * @test * @dataProvider sampleLocaleIdentifiers */ public function detectingBestMatchingLocaleFromLocaleIdentifierWorksCorrectly($localeIdentifier, $expectedResult) { $locale = $this->detector->detectLocaleFromLocaleTag($localeIdentifier); $this->assertEquals($expectedResult, $locale); }