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


PHP Locale::parseLocale方法代码示例

本文整理汇总了PHP中Locale::parseLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP Locale::parseLocale方法的具体用法?PHP Locale::parseLocale怎么用?PHP Locale::parseLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Locale的用法示例。


在下文中一共展示了Locale::parseLocale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getNameFormat

 /**
  * Get name format based on locale, if locale is not passed locale from system configuration will be used.
  *
  * @param string|null $locale
  * @throws \RuntimeException
  */
 public function getNameFormat($locale = null)
 {
     if (!$locale) {
         $locale = $this->localeSettings->getLocale();
     }
     $nameFormats = $this->localeSettings->getNameFormats();
     // match by locale (for example - "fr_CA")
     if (isset($nameFormats[$locale])) {
         return $nameFormats[$locale];
     }
     // match by locale language (for example - "fr")
     $localeParts = \Locale::parseLocale($locale);
     if (isset($localeParts[\Locale::LANG_TAG])) {
         $match = $localeParts[\Locale::LANG_TAG];
         if (isset($match, $nameFormats[$match])) {
             return $nameFormats[$match];
         }
     }
     // match by default locale in system configuration settings
     $match = $this->localeSettings->getLocale();
     if ($match !== $locale && isset($nameFormats[$match])) {
         return $nameFormats[$match];
     }
     // fallback to default constant locale
     $match = LocaleConfiguration::DEFAULT_LOCALE;
     if (isset($nameFormats[$match])) {
         return $nameFormats[$match];
     }
     throw new \RuntimeException(sprintf('Cannot get name format for "%s"', $locale));
 }
开发者ID:Maksold,项目名称:platform,代码行数:36,代码来源:NameFormatter.php

示例2: parse

 /**
  * Build locale object from a string.
  *
  * @param string $locale The locale as string
  *
  * @return Locale A Locale object
  */
 public static function parse($locale)
 {
     if (empty($locale)) {
         throw new \InvalidArgumentException('Locale string can not be empty');
     }
     $result = \Locale::parseLocale($locale);
     if (!is_array($result)) {
         throw new \RuntimeException(sprintf('Unable to parse locale "%s"', $locale));
     }
     $language = null;
     $region = null;
     $variants = array();
     foreach ($result as $key => $value) {
         if ('language' === $key) {
             $language = new Language($value);
         } elseif ('region' === $key) {
             $region = new Region($value);
         } elseif (0 === strpos($key, 'variant')) {
             $variants[] = new Variant($value);
         }
     }
     if (null === $language) {
         throw new \RuntimeException(sprintf('Unable to retrieve a valid language for locale "%s"', $locale));
     }
     return new self($language, $region, $variants);
 }
开发者ID:andreaswarnaar,项目名称:openl10n,代码行数:33,代码来源:Locale.php

示例3: parseHeader

 /**
  * Parse header
  *
  * @param   null|\Zend\Http\Header\AcceptLanguage   $header
  * @return  array
  */
 public function parseHeader($header)
 {
     $locales = array();
     $controller = $this->getController();
     if ($controller instanceof ServiceLocatorAwareInterface) {
         $availables = $controller->getServiceLocator()->get('Locale')->getAvailableLocales();
     } else {
         $availables = array(IntlLocale::getDefault());
     }
     if ($header instanceof AcceptLanguage) {
         foreach ($header->getPrioritized() as $part) {
             if ($part instanceof LanguageFieldValuePart) {
                 $locale = IntlLocale::parseLocale($part->getLanguage());
                 $key = $locale['language'];
                 if (isset($locale['region'])) {
                     $key .= '_' . $locale['region'];
                 }
                 if ($availables) {
                     $key = IntlLocale::lookup($availables, $key, false, '');
                 }
                 if ($key) {
                     $locales[$key] = max($part->getPriority(), empty($locales[$key]) ? 0 : $locales[$key]);
                 }
             }
         }
     }
     return $locales;
 }
开发者ID:gridguyz,项目名称:zork,代码行数:34,代码来源:Locale.php

示例4: setSessionLanguage

 /**
  * set Language to Session
  * 
  * @param string $lang Requested language
  */
 protected function setSessionLanguage($lang)
 {
     session()->set('applocale', $lang);
     $locale = \Locale::parseLocale($lang);
     session()->set('language', $locale['language']);
     $this->log->info("Language Switched:{$locale['language']}");
 }
开发者ID:ancchaimongkon,项目名称:timegrid,代码行数:12,代码来源:LanguageController.php

示例5: __construct

 public function __construct($locale)
 {
     $this->localeArray = Locale::parseLocale($locale);
     $this->localeString = Locale::composeLocale($this->localeArray);
     $this->initMonths();
     $this->initDays();
     $this->initPattern();
 }
开发者ID:jou,项目名称:ymc-components,代码行数:8,代码来源:date_format_symbols.php

示例6: 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

示例7: switchLang

 /**
  * Switch Language
  *
  * @param  string  $lang    Language iso code
  * @param  Session $session Session Facade
  * @return Redirect         HTTP Redirect
  */
 public function switchLang($lang)
 {
     $this->log->info("Language switch Request to {$lang}");
     if (array_key_exists($lang, config()->get('languages'))) {
         $this->log->info('Language Switched');
         session()->set('applocale', $lang);
         $locale = \Locale::parseLocale($lang);
         session()->set('language', $locale['language']);
     }
     return redirect()->back();
 }
开发者ID:martinsv,项目名称:timegrid,代码行数:18,代码来源:LanguageController.php

示例8: normalizeLocale

 /**
  * Normalize locale
  *
  * @param string $locale
  * @return string
  */
 public static function normalizeLocale($locale)
 {
     $parsed = IntlLocale::parseLocale($locale);
     if (empty($parsed) || empty($parsed['language'])) {
         return null;
     }
     $result = $parsed['language'];
     if (!empty($parsed['region'])) {
         $result .= '_' . strtoupper($parsed['region']);
     }
     return $result;
 }
开发者ID:gridguyz,项目名称:zork,代码行数:18,代码来源:AdminLocale.php

示例9: cleanLocale

 /**
  * Clean locale leaving only language and script
  *
  * @param string $locale
  * @return string
  */
 protected function cleanLocale($locale)
 {
     $localeParts = \Locale::parseLocale($locale);
     $cleanLocaleParts = [];
     if (isset($localeParts['language'])) {
         $cleanLocaleParts['language'] = $localeParts['language'];
     }
     if (isset($localeParts['script'])) {
         $cleanLocaleParts['script'] = $localeParts['script'];
     }
     return \Locale::composeLocale($cleanLocaleParts);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:18,代码来源:DataBundle.php

示例10: actionScan

 public function actionScan($argv)
 {
     if (count($argv) < 1) {
         exit("usage: [1;34mgini i18n scan[0m [<locales>]\n");
     }
     $info = \Gini\Core::moduleInfo(APP_ID);
     if (!isset($info->id)) {
         echo "[1;34mgini i18n scan[0m: Invalid app path!\n";
         exit;
     }
     $path = $info->path;
     $domain = str_replace('/', '-', $info->id);
     $l10n_path = $path . '/' . RAW_DIR . '/l10n';
     \Gini\File::ensureDir($l10n_path);
     $l10n_template = $l10n_path . '/template.pot';
     if (file_exists($l10n_template)) {
         unlink($l10n_template);
     }
     $keywords = '--keyword=T';
     //$package = sprintf('--package-name=%s --package-version=%s',
     $cmd = sprintf('cd %s && find class view -name "*.php" -o -name "*.phtml" | xargs xgettext -LPHP %s --from-code=UTF-8 -i --copyright-holder=%s --foreign-user --package-name=%s --package-version=%s --msgid-bugs-address=%s -o %s', escapeshellarg($path), $keywords, escapeshellarg($info->author ?: 'Gini Team'), escapeshellarg($info->id), escapeshellarg($info->version), escapeshellarg($info->email ?: 'l10n@geneegroup.com'), escapeshellarg($l10n_template));
     passthru($cmd);
     // extract msgid ""{context}\004{txt} to msgctxt and msgid
     $cmd = sprintf("sed 's/msgid   \"\\(.*\\)''/msgctxt \"\\1\"\\nmsgid \"/g' %s", escapeshellarg($l10n_template));
     // echo $cmd . "\n"; die;
     file_put_contents($l10n_template, `{$cmd}`);
     $locales = $argv;
     foreach (glob($l10n_path . '/*.po') as $fname) {
         $locale = basename($fname, '.po');
         $locales[] = $locale;
     }
     foreach (array_unique($locales) as $locale) {
         $locale_arr = \Locale::parseLocale($locale);
         if (!isset($locale_arr['language'])) {
             continue;
         }
         $l10n_pofile = $l10n_path . '/' . $locale . '.po';
         if (!file_exists($l10n_pofile)) {
             $cmd = sprintf('msginit --no-translator -o %1$s -i %2$s -l %3$s', escapeshellarg($l10n_pofile), escapeshellarg($l10n_template), escapeshellarg($locale));
         } else {
             $cmd = sprintf('msgmerge --update --suffix=none --no-fuzzy-matching -q %1$s %2$s', escapeshellarg($l10n_pofile), escapeshellarg($l10n_template));
         }
         passthru($cmd);
     }
     echo "done.\n";
     //merge po file to different locale directory
 }
开发者ID:HuangStomach,项目名称:gini,代码行数:47,代码来源:I18N.php

示例11: toIso

 /**
  * Returns the ISO representation of the locale
  * ("lang-REGION" as opposed to its canonical "lang_REGION")
  *
  * @return string
  */
 public function toIso()
 {
     $locale = IntlLocale::parseLocale($this->getCurrent());
     $result = $locale['language'];
     if (!empty($locale['region'])) {
         $result .= '-' . $locale['region'];
     }
     return $result;
 }
开发者ID:gridguyz,项目名称:zork,代码行数:15,代码来源:Locale.php

示例12: setDefault

 /**
  * Sets the locale to the given locale
  *
  * This function will also set the "old" setlocale, mainly timezone support for PHP5.3 - PHP5.5
  *
  * @param string $locale Locale we want to set in RFC 4646 format
  * @return string Returns the setted locale
  */
 public function setDefault($locale)
 {
     $result = '';
     if (!empty($locale)) {
         $locale = \Locale::parseLocale($locale);
         $locale = \Locale::composeLocale($locale);
         \Locale::setDefault($locale);
         $result = $this->getDefault();
         $this->_setOptions();
     }
     return $result;
 }
开发者ID:unreal4u,项目名称:localization,代码行数:20,代码来源:localization.php

示例13: decompose

 /**
  * Parses a locale string and returns an array of key-value locale tags.
  *
  * @uses Locale
  *
  * @param string $locale
  * @return string
  */
 public static function decompose($locale)
 {
     return \Locale::parseLocale($locale);
 }
开发者ID:titon,项目名称:g11n,代码行数:12,代码来源:G11n.php

示例14: normalizeLocale

 /**
  * Normalize locale
  *
  * @param   string  $locale
  * @return  string
  */
 public static function normalizeLocale($locale)
 {
     if (empty($locale)) {
         return '';
     }
     $parsed = IntlLocale::parseLocale($locale);
     // @codeCoverageIgnoreStart
     if (empty($parsed) || empty($parsed['language'])) {
         return $locale;
     }
     // @codeCoverageIgnoreEnd
     $result = strtolower($parsed['language']);
     if (!empty($parsed['region'])) {
         $result .= '_' . strtoupper($parsed['region']);
     }
     return $result;
 }
开发者ID:gridguyz,项目名称:zork,代码行数:23,代码来源:Locale.php

示例15: setLocale

 public function setLocale($category, $candidates)
 {
     $categoryName = self::categoryToName($category);
     if (!is_array($candidates)) {
         $candidates = array($candidates);
     }
     if (!count($candidates)) {
         throw new \InvalidArgumentException('Invalid locale');
     }
     $base = $this->getBaseDir($this->component);
     $newLocale = null;
     foreach ($candidates as $candidate) {
         if (!is_string($candidate)) {
             throw new \InvalidArgumentException('Invalid locale');
         }
         $locale = \Locale::parseLocale($candidate);
         if (!is_array($locale) || !isset($locale['language'])) {
             throw new \InvalidArgumentException('Invalid locale');
         }
         // For anything else than LC_MESSAGES,
         // we take the first candidate as is.
         if ($categoryName != 'LC_MESSAGES') {
             $newLocale = $candidate;
         }
         if ($newLocale !== null) {
             continue;
         }
         $catalog = str_replace('\\', '_', ltrim($this->component, '\\'));
         if (isset($locale['region'])) {
             $normLocale = $locale['language'] . '_' . $locale['region'];
             $file = $base . DIRECTORY_SEPARATOR . $normLocale . DIRECTORY_SEPARATOR . $categoryName . DIRECTORY_SEPARATOR . $catalog . '.mo';
             if (file_exists($file)) {
                 $newLocale = $normLocale;
                 continue;
             }
         }
         $file = $base . DIRECTORY_SEPARATOR . $locale['language'] . DIRECTORY_SEPARATOR . $categoryName . DIRECTORY_SEPARATOR . $catalog . '.mo';
         if (file_exists($file)) {
             $newLocale = $locale['language'];
             continue;
         }
     }
     if ($newLocale === null) {
         $newLocale = 'en_US';
     }
     $this->locales[$category] = $newLocale;
     return $newLocale;
 }
开发者ID:erebot,项目名称:intl,代码行数:48,代码来源:Intl.php


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