Neos\Flow\I18n\Detector::detectLocaleFromLocaleTag PHP Метод

detectLocaleFromLocaleTag() публичный Метод

Returns best-matching Locale object based on the locale identifier provided as parameter. System default locale will be returned if no successful matches were done.
public detectLocaleFromLocaleTag ( string $localeIdentifier ) : Locale
$localeIdentifier string The locale identifier as used in Locale class
Результат Locale 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();
        }
    }

Usage Example

 /**
  * @test
  * @dataProvider sampleLocaleIdentifiers
  */
 public function detectingBestMatchingLocaleFromLocaleIdentifierWorksCorrectly($localeIdentifier, $expectedResult)
 {
     $locale = $this->detector->detectLocaleFromLocaleTag($localeIdentifier);
     $this->assertEquals($expectedResult, $locale);
 }