本文整理汇总了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);
}
示例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;
}
示例3: __construct
public function __construct($locale)
{
$this->localeArray = Locale::parseLocale($locale);
$this->localeString = Locale::composeLocale($this->localeArray);
$this->initMonths();
$this->initDays();
$this->initPattern();
}
示例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;
}
示例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);
}
示例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];
}
示例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);
}
示例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);
}
示例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);
}
示例10: of
public static function of($language, $region = '')
{
return new Locale(\Locale::composeLocale(['language' => $language, 'region' => $region]));
}
示例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");
}
}
示例12: normalize
public static function normalize($locale)
{
return str_replace('_', '-', \Locale::composeLocale(\Locale::parseLocale($locale)));
}
示例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);
}
示例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;
}