예제 #1
0
파일: Detector.php 프로젝트: nxpthx/FLOW3
 /**
  * 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 \TYPO3\FLOW3\I18n\Locale Best-matching existing Locale instance
  * @api
  */
 public function detectLocaleFromHttpHeader($acceptLanguageHeader)
 {
     $acceptableLanguages = \TYPO3\FLOW3\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 \TYPO3\FLOW3\I18n\Locale($languageIdentifier);
         } catch (\TYPO3\FLOW3\I18n\Exception\InvalidLocaleIdentifierException $exception) {
             continue;
         }
         $bestMatchingLocale = $this->localeCollection->findBestMatchingLocale($locale);
         if ($bestMatchingLocale !== NULL) {
             return $bestMatchingLocale;
         }
     }
     return $this->localizationService->getConfiguration()->getDefaultLocale();
 }
예제 #2
0
 /**
  * @test
  * @dataProvider sampleHttpAcceptLanguageHeaders
  */
 public function httpAcceptLanguageHeadersAreParsedCorrectly($acceptLanguageHeader, array $expectedResult)
 {
     $languages = \TYPO3\FLOW3\I18n\Utility::parseAcceptLanguageHeader($acceptLanguageHeader);
     $this->assertEquals($expectedResult, $languages);
 }