本文整理汇总了PHP中Locale::canonicalize方法的典型用法代码示例。如果您正苦于以下问题:PHP Locale::canonicalize方法的具体用法?PHP Locale::canonicalize怎么用?PHP Locale::canonicalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Locale
的用法示例。
在下文中一共展示了Locale::canonicalize方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionZoneData
public function actionZoneData($locale = '')
{
if ($locale) {
$locale = \Locale::canonicalize($locale);
}
return $this->render('zone-data', ['locale' => $locale]);
}
示例2: actionIndex
public function actionIndex($locale = '')
{
if ($locale) {
$locale = \Locale::canonicalize($locale);
}
return $this->render('index', ['locale' => $locale, 'spelloutRules' => $this->getRules($locale, \NumberFormatter::SPELLOUT), 'ordinalRules' => $this->getRules($locale, \NumberFormatter::ORDINAL), 'durationRules' => $this->getRules($locale, \NumberFormatter::DURATION), 'pluralCardinalRules' => $this->getPluralCardinalRules($locale), 'pluralCardinalExample' => $this->getPluralCardinalExample($locale), 'pluralOrdinalRules' => $this->getPluralOrdinalRules($locale), 'pluralOrdinalExample' => $this->getPluralOrdinalExample($locale)]);
}
示例3: convert
public function convert($locale)
{
$parts = \Locale::parseLocale($locale);
if (!isset($parts['region'])) {
$parts['region'] = $this->country;
}
$locale = \Locale::canonicalize(\Locale::composeLocale($parts));
return $locale;
}
示例4: getCanonicalLocale
/**
* @return string
*/
public static function getCanonicalLocale()
{
try {
$locale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
return \Locale::canonicalize($locale);
} catch (\Exception $e) {
return static::getDefaultLocale();
}
}
示例5: getBestLocale
private function getBestLocale(Request $request)
{
$acceptLanguage = $request->server->get('HTTP_ACCEPT_LANGUAGE');
if (!$acceptLanguage) {
return $this->defaultLocale;
}
$negotiator = new \Negotiation\LanguageNegotiator();
$locale = $negotiator->getBest($acceptLanguage);
if (!$locale) {
return $this->defaultLocale;
}
return \Locale::canonicalize($locale->getValue());
}
示例6: getLocale
protected function getLocale(ServiceLocatorInterface $services)
{
if ($services->has('LocaleManager')) {
$localeManager = $services->get('LocaleManager');
if ($localeManager instanceof LocaleManagerInterface) {
return $localeManager->getLocale();
}
}
// Try to get the locale through the translator
if ($services->has('Translator')) {
$translator = $services->get('Translator');
if ($translator instanceof \Zend\Mvc\I18n\Translator) {
$translator = $translator->getTranslator();
}
if (method_exists($translator, 'getLocale')) {
return \Locale::canonicalize($translator->getLocale());
}
}
// If everything went wrong get the default locale
return \Locale::getDefault();
}
示例7: __construct
/**
* Creates a locale from a locale name.
*
* @param string $localeName The name of the locale (case-insensitive).
*/
public function __construct($localeName)
{
assert('is_cstring($localeName)', vs(isset($this), get_defined_vars()));
assert('self::isValid($localeName)', vs(isset($this), get_defined_vars()));
$this->m_name = Locale::canonicalize($localeName);
}
示例8: localeExists
/**
*
* {@inheritDoc}
*
* @see \Thunderhawk\API\Component\Translator\TranslatorInterface::localeExists()
*/
public function localeExists($locale)
{
$locale = \Locale::canonicalize($locale);
return Languages::findFirstByLocale($locale) !== false;
}
示例9: translate
/**
* Returns translated string
*
* @param string $key The key to translate
* @param array $params The string values to passe in
* @param string $target The target locale string if diferent than current
*
* @return string The resulting string
*/
public function translate($key, $params = array(), $target = null)
{
// Load defauts
$current = $this->current;
$directory = $this->directory . DIRECTORY_SEPARATOR . $current;
$params = (array) $params;
// Validate and load different $target
if (!empty($target) && $target != $current) {
$current = $target;
$directory = $this->directory . DIRECTORY_SEPARATOR . $current;
// Validate locale and translations directory
if (\Locale::canonicalize($current) === null || !is_dir($this->directory . DIRECTORY_SEPARATOR . $current)) {
throw new DualityException("Error Locale: target code ", DualityException::E_LOCALE_NOTFOUND);
}
}
// Finally, return result
$storage = new Storage();
$storage->importArray(include $directory . DIRECTORY_SEPARATOR . 'messages.php');
return \MessageFormatter::formatMessage($current, $storage->get($key), $params);
}
示例10: translate
/**
* Translate the $resource
*
* @param string $locale
* @param TranslatableResource $resource
*
* @throws \IntlException
* @return string
*/
public function translate($locale, TranslatableResource $resource)
{
$canonicalLocale = \Locale::canonicalize($locale);
$messageFormatter = new \MessageFormatter($canonicalLocale, $this->retrievePattern($canonicalLocale, $resource->getKey()));
return $messageFormatter->format($resource->getParameters());
}
示例11: hasLocale
/**
* Check whether locale is available
*
* @param string $locale
*/
public function hasLocale($locale)
{
return in_array(\Locale::canonicalize($locale), $this->getLocales());
}