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


PHP Locale::composeLocale方法代码示例

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


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

示例1: build

 /**
  * @param array $subtags
  *
  * @return Locale
  *
  * @throws \InvalidArgumentException
  */
 private static function build(array $subtags)
 {
     if (!isset($subtags['language'])) {
         throw new \InvalidArgumentException('Invalid locale.');
     }
     if (preg_match('/^[a-zA-Z]{2,8}$/', $subtags['language']) == 0) {
         throw new \InvalidArgumentException('Invalid language subtag.');
     }
     if (isset($subtags['script'])) {
         if (preg_match('/^[a-zA-Z]{4}$/', $subtags['script']) == 0) {
             throw new \InvalidArgumentException('Invalid script subtag.');
         }
     }
     if (isset($subtags['region'])) {
         if (preg_match('/^[a-zA-Z]{2}|[0-9]{3}$/', $subtags['region']) == 0) {
             throw new \InvalidArgumentException('Invalid region subtag.');
         }
     }
     for ($i = 0; isset($subtags[$key = 'variant' . $i]); $i++) {
         if (preg_match('/^[0-9][0-9a-zA-Z]{3}|[0-9a-zA-Z]{5,8}$/', $subtags[$key]) == 0) {
             throw new \InvalidArgumentException('Invalid variant subtag.');
         }
     }
     $locale = \Locale::composeLocale($subtags);
     // Another round trip to canonicalize the locale with parseLocale().
     $subtags = \Locale::parseLocale($locale);
     $locale = \Locale::composeLocale($subtags);
     return new Locale($locale, $subtags);
 }
开发者ID:brick,项目名称:brick,代码行数:36,代码来源:Locale.php

示例2: getLocale

 public function getLocale()
 {
     if (!isset($this->locale)) {
         if (isset(self::$LOCALE__DEFAULT)) {
             $this->locale = self::$LOCALE__DEFAULT;
         } else {
             global $conf;
             global $language;
             if (!isset($conf['site_default_country'])) {
                 $conf['site_default_country'] = 'us';
             }
             $country = isset($conf['site_default_country']) ? trim($conf['site_default_country']) : '';
             if ($country === '') {
                 throw new IllegalStateException(t("Default country was not defined. Go to 'Configuration' | 'Regional and language' | 'Regional settings' to set default country"));
             }
             $localeSubTags = array('language' => $language->language, 'region' => $country);
             $locale = Locale::composeLocale($localeSubTags);
             if ($this->isWindows()) {
                 // the following line was not needed on Windows XP
                 // if we do not include it on Windows 7 localeconv() would return empty value for almost all properties
                 $uselessLocale = setlocale(LC_ALL, NULL);
                 // It is expected to get en-US instead of en_US on Windows
                 $locale = str_replace('_', '-', $locale);
             }
             $this->locale = $locale;
         }
     }
     return $this->locale;
 }
开发者ID:ecs-hk,项目名称:Checkbook,代码行数:29,代码来源:Environment.php

示例3: __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

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

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

示例6: availableTranslationsAction

 /**
  * @Route("/available-translations", name="oro_translation_available_translations")
  * @Template
  */
 public function availableTranslationsAction()
 {
     $statisticProvider = $this->get('oro_translation.statistic_provider');
     $cm = $this->get('oro_config.global');
     $stats = $statisticProvider->get();
     $defaultValue = $cm->get(LanguageType::CONFIG_KEY, true);
     // @TODO find better solution
     if ($defaultValue == 'en') {
         $defaultValue = \Locale::composeLocale(['language' => $defaultValue, 'region' => 'US']);
     }
     $configValues = $cm->get(TranslationStatusInterface::CONFIG_KEY);
     $localeChoices = Intl::getLocaleBundle()->getLocaleNames();
     return ['statistic' => $stats, 'defaultLanguage' => $defaultValue, 'config' => (array) $configValues, 'locale' => $localeChoices];
 }
开发者ID:Maksold,项目名称:platform,代码行数:18,代码来源:ServiceController.php

示例7: prepareLocale

    protected function prepareLocale() {
        global $conf;
        global $language;

        $country = isset($conf['site_default_country']) ? trim($conf['site_default_country']) : '';
        if ($country === '') {
            $country = 'us';
            LogHelper::log_warn(t("Default country was not defined. Go to 'Configuration' | 'Regional and language' | 'Regional settings' to set default country"));
        }

        $localeSubTags = array('language' => $language->language, 'region' => $country);

        return Locale::composeLocale($localeSubTags);
    }
开发者ID:reisystems-india,项目名称:GovDashboard-Community,代码行数:14,代码来源:Environment.php

示例8: fromComponents

 /**
  * Creates a locale from a language code and, optionally, a country/region code, a script code, and variants.
  *
  * If the locale is to indicate any variants, the variants follow the script code's argument when calling this
  * method.
  *
  * @param  string $language The two-letter ISO 639 language code (case-insensitive).
  * @param  string $region **OPTIONAL. Default is** *none*. The two-letter ISO 3166 (or ISO 639) country/region
  * code (case-insensitive).
  * @param  string $script **OPTIONAL. Default is** *none*. The four-letter script code (case-insensitive).
  *
  * @return CULocale The new locale.
  */
 public static function fromComponents($language, $region = null, $script = null)
 {
     assert('is_cstring($language) && (!isset($region) || is_cstring($region)) && ' . '(!isset($script) || is_cstring($script))', vs(isset($this), get_defined_vars()));
     assert('CRegex::find($language, "/^[a-z]{2,3}\\\\z/i")', vs(isset($this), get_defined_vars()));
     assert('!isset($region) || CRegex::find($region, "/^[a-z]{2,3}\\\\z/i")', vs(isset($this), get_defined_vars()));
     assert('!isset($script) || CRegex::find($script, "/^[a-z]{4}\\\\z/i")', vs(isset($this), get_defined_vars()));
     $funcNumArgs = func_num_args();
     assert('$funcNumArgs - 3 <= 15', vs(isset($this), get_defined_vars()));
     // the variants are limited by 15
     $subtags = CMap::make();
     $subtags[Locale::LANG_TAG] = $language;
     if (isset($region)) {
         $subtags[Locale::REGION_TAG] = $region;
     }
     if (isset($script)) {
         $subtags[Locale::SCRIPT_TAG] = $script;
     }
     $variantIdx = 0;
     for ($i = 3; $i < func_num_args(); $i++) {
         $variant = func_get_arg($i);
         assert('is_cstring($variant)', vs(isset($this), get_defined_vars()));
         $subtags[Locale::VARIANT_TAG . $variantIdx] = $variant;
         $variantIdx++;
     }
     $localeName = Locale::composeLocale($subtags);
     return new self($localeName);
 }
开发者ID:nunodotferreira,项目名称:Phred,代码行数:40,代码来源:CULocale.php

示例9: compose

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

示例10: of

 public static function of($language, $region = '')
 {
     return new Locale(\Locale::composeLocale(['language' => $language, 'region' => $region]));
 }
开发者ID:celest-time,项目名称:prototype,代码行数:4,代码来源:Locale.php

示例11: updateLocaleSetting

function updateLocaleSetting($locale)
{
    global $error, $Settings, $success;
    if ($Settings->getSetting('locale') == $locale) {
        return true;
    }
    $newLocale = Locale::parseLocale($locale);
    // If ['language'] isn't set, then we can't pick a language, so whole Locale is invalid. Region part of Locale isn't as important as Language is. Could default to English if no langauge, so Region would work, but they could just append en_ to the locale themself
    if (isset($newLocale['language'])) {
        $locale = Locale::composeLocale($newLocale);
        if ($Settings->setSetting('locale', $locale)) {
            // Apply new locale so language displays correctly from now on
            \Grase\Locale::applyLocale($locale);
            $success[] = T_("Locale updated");
            AdminLog::getInstance()->log(T_("Locale updated to") . $locale);
        } else {
            $error[] = T_("Error updating Locale");
        }
    } else {
        $error[] = T_("Invalid Locale");
    }
}
开发者ID:KuberKode,项目名称:grase-www-portal,代码行数:22,代码来源:settings.php

示例12: normalize

 public static function normalize($locale)
 {
     return str_replace('_', '-', \Locale::composeLocale(\Locale::parseLocale($locale)));
 }
开发者ID:gossi,项目名称:propel-l10n-behavior,代码行数:4,代码来源:PropelL10n.php

示例13: composeLocale

 /**
  * Create a correctly ordered and delimited locale from subtags
  *
  * @param  array        $subtags an array containing a list of key-value
  *     pairs, where the keys identify the particular locale ID subtags, and
  *     the values are the associated subtag values.
  * @return LocaleFacade
  */
 public static function composeLocale(array $subtags)
 {
     $locale = IntlLocale::composeLocale($subtags);
     return new LocaleFacade($locale);
 }
开发者ID:ledgr,项目名称:localefacade,代码行数:13,代码来源:LocaleFacade.php

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


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