当前位置: 首页>>代码示例>>PHP>>正文


PHP Locale::canonicalize方法代码示例

本文整理汇总了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]);
 }
开发者ID:samdark,项目名称:intl-icu-data-tables,代码行数:7,代码来源:SiteController.php

示例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)]);
 }
开发者ID:mlzharov,项目名称:intl-icu-data-tables,代码行数:7,代码来源:SiteController.php

示例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;
 }
开发者ID:sphereio,项目名称:commercetools-sunrise-php,代码行数:9,代码来源:LocaleConverter.php

示例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();
     }
 }
开发者ID:chansig,项目名称:directoryindex,代码行数:12,代码来源:Translation.php

示例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());
 }
开发者ID:andreaswarnaar,项目名称:openl10n,代码行数:13,代码来源:LocaleListener.php

示例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();
 }
开发者ID:zend-modules,项目名称:localemanager_outdated,代码行数:21,代码来源:SendResponseListener.php

示例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);
 }
开发者ID:nunodotferreira,项目名称:Phred,代码行数:11,代码来源:CULocale.php

示例8: localeExists

 /**
  *
  * {@inheritDoc}
  *
  * @see \Thunderhawk\API\Component\Translator\TranslatorInterface::localeExists()
  */
 public function localeExists($locale)
 {
     $locale = \Locale::canonicalize($locale);
     return Languages::findFirstByLocale($locale) !== false;
 }
开发者ID:skullab,项目名称:area51,代码行数:11,代码来源:Translator.php

示例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);
 }
开发者ID:taviroquai,项目名称:duality,代码行数:29,代码来源:Localization.php

示例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());
 }
开发者ID:remi-san,项目名称:intl,代码行数:15,代码来源:ResourceTranslator.php

示例11: hasLocale

 /**
  * Check whether locale is available
  *
  * @param string $locale
  */
 public function hasLocale($locale)
 {
     return in_array(\Locale::canonicalize($locale), $this->getLocales());
 }
开发者ID:coolms,项目名称:locale,代码行数:9,代码来源:Detector.php


注:本文中的Locale::canonicalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。