/** * Internal function, returns a locale fallback list on detection * * @param string|\Zend\Locale\Locale $locale (Optional) Locale to work on * @param boolean $strict (Optional) Strict preparation * @throws \Zend\Locale\Exception\UnexpectedValueException When no locale is set which is only possible when the class was wrong extended * @return array */ private static function _prepareLocale($locale, $strict = false) { if ($locale instanceof self) { $locale = $locale->toString(); } if (is_array($locale)) { return ''; } if (empty(self::$_auto)) { self::$_browser = self::getBrowser(); self::$_environment = self::getEnvironment(); self::$_auto = self::getBrowser() + self::getEnvironment() + self::getFallback(); } if (!$strict) { if ($locale === 'browser') { $locale = self::$_browser; } if ($locale === 'environment') { $locale = self::$_environment; } if ($locale === 'fallback') { $locale = self::$_fallback; } if ($locale === 'auto' or $locale === null) { $locale = self::$_auto; } if (is_array($locale) === true) { $locale = key($locale); } } // This can only happen when someone extends Zend\Locale and erases the fallback if ($locale === null) { throw new Exception\UnexpectedValueException('Autodetection of Locale has been failed!'); } if (strpos($locale, '-') !== false) { $locale = strtr($locale, '-', '_'); } $parts = explode('_', $locale); if (!isset(self::$_localeData[$parts[0]])) { if (count($parts) == 1 && array_key_exists($parts[0], self::$_territoryData)) { return self::$_territoryData[$parts[0]]; } return ''; } foreach ($parts as $key => $value) { if (strlen($value) < 2 || strlen($value) > 3) { unset($parts[$key]); } } $locale = implode('_', $parts); return (string) $locale; }
/** * Internal function, returns a single locale on detection * * @param string|\Zend\Locale\Locale $locale (Optional) Locale to work on * @param boolean $strict (Optional) Strict preparation * @throws \Zend\Locale\Exception When no locale is set which is only possible when the class was wrong extended * @return string */ private static function _prepareLocale($locale, $strict = false) { if ($locale instanceof Locale) { $locale = $locale->toString(); } if (is_array($locale)) { return ''; } if (empty(self::$_auto) === true) { self::$_browser = self::getBrowser(); self::$_environment = self::getEnvironment(); self::$_breakChain = true; self::$_auto = self::getBrowser() + self::getEnvironment() + self::getDefault(); } if (!$strict) { if ($locale === 'browser') { $locale = self::$_browser; } if ($locale === 'environment') { $locale = self::$_environment; } if ($locale === 'default') { $locale = self::$_default; } if ($locale === 'auto' or $locale === null) { $locale = self::$_auto; } if (is_array($locale) === true) { $locale = key($locale); } } // This can only happen when someone extends Zend_Locale and erases the default if ($locale === null) { throw new Exception('Autodetection of Locale has been failed!'); } if (strpos($locale, '-') !== false) { $locale = strtr($locale, '-', '_'); } $parts = explode('_', $locale); if (!isset(self::$_localeData[$parts[0]])) { return ''; } foreach ($parts as $key => $value) { if (strlen($value) < 2 || strlen($value) > 3) { unset($parts[$key]); } } $locale = implode('_', $parts); return (string) $locale; }