Esempio n. 1
0
 /**
  * Tries to get a locale from the provided accept language
  * @param zibo\library\i18n\locale\io\LocaleIO $io
  * @param string $acceptLanguage
  * @return null|zibo\library\i18n\locale\Locale the locale
  */
 private function getLocaleFromAcceptLanguage(LocaleIO $io, $acceptLanguage)
 {
     if (strpos($acceptLanguage, self::SEPARATOR_PARAMETERS) === false) {
         $locale = $acceptLanguage;
     } else {
         list($locale, $parameters) = explode(self::SEPARATOR_PARAMETERS, $acceptLanguage);
     }
     if (strpos($locale, self::SEPARATOR_TERRITORY) === false) {
         $language = $locale;
         $territory = '';
     } else {
         list($language, $territory) = explode(self::SEPARATOR_TERRITORY, $locale);
     }
     $language = strtolower($language);
     $territory = strtoupper($territory);
     if (!empty($territory)) {
         $localeCode = $language . '_' . $territory;
         $locale = $io->getLocale($localeCode);
         if ($locale) {
             return $locale;
         }
     }
     $locale = $io->getLocale($language);
     if ($locale) {
         return $locale;
     }
     return null;
 }
Esempio n. 2
0
 /**
  * Initializes the available locales
  * @return null
  */
 private function initLocales()
 {
     if (!isset($this->locales)) {
         $this->locales = $this->io->getLocales();
     }
 }