/**
  * Determines which locale to use, based on the HTTP Accept-Language header.
  * @param zibo\library\i18n\locale\LocaleManager $manager The locale manager
  * @return null|zibo\library\i18n\locale\Locale the locale
  */
 public function getLocale(LocaleManager $manager)
 {
     $request = $this->zibo->getRequest();
     if (!$request) {
         return null;
     }
     $fallbackLanguages = array();
     $acceptedLanguages = $request->getAcceptLanguage();
     foreach ($acceptedLanguages as $acceptedLanguage => $null) {
         if (strpos($acceptedLanguage, self::SEPARATOR_TERRITORY) === false) {
             $locale = strtolower($acceptedLanguage);
         } else {
             list($language, $territory) = explode(self::SEPARATOR_TERRITORY, $acceptedLanguage);
             $language = strtolower($language);
             $locale = $language . '_' . strtoupper($territory);
             $fallbackLanguages[$language] = true;
         }
         if ($manager->hasLocale($locale)) {
             return $manager->getLocale($locale);
         }
     }
     foreach ($fallbackLanguages as $locale => $null) {
         if ($manager->hasLocale($locale)) {
             return $manager->getLocale($locale);
         }
     }
     return null;
 }
Beispiel #2
0
 /**
  * Gets all the available locales
  * @return array
  */
 public function getLocales()
 {
     return $this->localeManager->getLocales();
 }