public function detectLocaleFromHttpHeader($acceptLanguageHeader)
    {
        $acceptableLanguages = I18n\Utility::parseAcceptLanguageHeader($acceptLanguageHeader);

        if ($acceptableLanguages === false) {
            return $this->localizationService->getConfiguration()->getDefaultLocale();
        }

        foreach ($acceptableLanguages as $languageIdentifier) {
            if ($languageIdentifier === '*') {
                return $this->localizationService->getConfiguration()->getDefaultLocale();
            }

            try {
                $locale = new Locale($languageIdentifier);
            } catch (Exception\InvalidLocaleIdentifierException $exception) {
                continue;
            }

            $bestMatchingLocale = $this->localeCollection->findBestMatchingLocale($locale);

            if ($bestMatchingLocale !== null) {
                return $bestMatchingLocale;
            }
        }

        return $this->localizationService->getConfiguration()->getDefaultLocale();
    }
public function detectLocaleFromHttpHeader($acceptLanguageHeader)
    {
        $acceptableLanguages = I18n\Utility::parseAcceptLanguageHeader($acceptLanguageHeader);

        if ($acceptableLanguages === false) {
            return $this->localizationService->getConfiguration()->getDefaultLocale();
        }

        foreach ($acceptableLanguages as $languageIdentifier) {
            if ($languageIdentifier === '*') {
                return $this->localizationService->getConfiguration()->getDefaultLocale();
            }

            try {
                $locale = new Locale($languageIdentifier);
            } catch (Exception\InvalidLocaleIdentifierException $exception) {
                continue;
            }

            $bestMatchingLocale = $this->localeCollection->findBestMatchingLocale($locale);

            if ($bestMatchingLocale !== null) {
                return $bestMatchingLocale;
            }
        }

        return $this->localizationService->getConfiguration()->getDefaultLocale();
    }
public function detectLocaleFromHttpHeader ( $ acceptLanguageHeader ) { $ acceptableLanguages = I18n \ Utility :: parseAcceptLanguageHeader ( $ acceptLanguageHeader ) ; if ( $ acceptableLanguages === false ) { return $ this -> localizationService -> getConfiguration ( ) -> getDefaultLocale ( ) ; } foreach ( $ acceptableLanguages as $ languageIdentifier ) { if ( $ languageIdentifier === '*' ) { return $ this -> localizationService -> getConfiguration ( ) -> getDefaultLocale ( ) ; } try { $ locale = new Locale ( $ languageIdentifier ) ; } catch ( Exception \ InvalidLocaleIdentifierException $ exception ) { continue ; } $ bestMatchingLocale = $ this -> localeCollection -> findBestMatchingLocale ( $ locale ) ; if ( $ bestMatchingLocale !== null ) { return $ bestMatchingLocale ; } } return $ this -> localizationService -> getConfiguration ( ) -> getDefaultLocale ( ) ; }
Returns best-matching Locale object based on the Accept-Language header
provided as parameter. System default locale will be returned if no
successful matches were done.

@param string $acceptLanguageHeader The Accept-Language HTTP header
@return Locale Best-matching existing Locale instance
@api
Returns best - matching Locale object based on the Accept - Language header provided as parameter . System default locale will be returned if no successful matches were done .