本文整理匯總了PHP中Locale::getAllVariants方法的典型用法代碼示例。如果您正苦於以下問題:PHP Locale::getAllVariants方法的具體用法?PHP Locale::getAllVariants怎麽用?PHP Locale::getAllVariants使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Locale
的用法示例。
在下文中一共展示了Locale::getAllVariants方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: generateLocaleName
private function generateLocaleName($locale, $displayLocale)
{
$name = null;
$lang = \Locale::getPrimaryLanguage($locale);
$script = \Locale::getScript($locale);
$region = \Locale::getRegion($locale);
$variants = \Locale::getAllVariants($locale);
// Currently the only available variant is POSIX, which we don't want
// to include in the list
if (count($variants) > 0) {
return null;
}
// Some languages are translated together with their region,
// i.e. "en_GB" is translated as "British English"
// we don't include these languages though because they mess up
// the name sorting
// $name = $this->langBundle->getLanguageName($displayLocale, $lang, $region);
// Some languages are simply not translated
// Example: "az" (Azerbaijani) has no translation in "af" (Afrikaans)
if (null === ($name = $this->languageBundle->getLanguageName($lang, null, $displayLocale))) {
return null;
}
// "as" (Assamese) has no "Variants" block
//if (!$langBundle->get('Variants')) {
// continue;
//}
$extras = array();
// Discover the name of the script part of the locale
// i.e. in zh_Hans_MO, "Hans" is the script
if ($script) {
// Some scripts are not translated into every language
if (null === ($scriptName = $this->languageBundle->getScriptName($script, $lang, $displayLocale))) {
return null;
}
$extras[] = $scriptName;
}
// Discover the name of the region part of the locale
// i.e. in de_AT, "AT" is the region
if ($region) {
// Some regions are not translated into every language
if (null === ($regionName = $this->regionBundle->getCountryName($region, $displayLocale))) {
return null;
}
$extras[] = $regionName;
}
if (count($extras) > 0) {
// Remove any existing extras
// For example, in German, zh_Hans is "Chinesisch (vereinfacht)".
// The latter is the script part which is already included in the
// extras and will be appended again with the other extras.
if (preg_match('/^(.+)\\s+\\([^\\)]+\\)$/', $name, $matches)) {
$name = $matches[1];
}
$name .= ' (' . implode(', ', $extras) . ')';
}
return $name;
}
示例2: variants
/**
* Returns the variants of a locale.
*
* @return CArrayObject The locale's variants of type `CUStringObject` (always uppercased).
*/
public function variants()
{
assert('$this->hasVariants()', vs(isset($this), get_defined_vars()));
$variants = Locale::getAllVariants($this->m_name);
if (is_cmap($variants)) {
return oop_a(CArray::fromPArray($variants));
} else {
return oop_a(CArray::make());
}
}
示例3: load_resource_bundle
// Don't include ICU's root resource bundle
if ($translatedLocale === 'root') {
continue;
}
$langBundle = load_resource_bundle($translatedLocale, $langDir);
$regionBundle = load_resource_bundle($translatedLocale, $regionDir);
$localeNames = array();
foreach ($supportedLocales as $supportedLocale) {
// Don't include ICU's root resource bundle
if ($supportedLocale === 'root') {
continue;
}
$lang = \Locale::getPrimaryLanguage($supportedLocale);
$script = \Locale::getScript($supportedLocale);
$region = \Locale::getRegion($supportedLocale);
$variants = \Locale::getAllVariants($supportedLocale);
// Currently the only available variant is POSIX, which we don't want
// to include in the list
if (count($variants) > 0) {
continue;
}
$langName = $langBundle->get('Languages')->get($lang);
$extras = array();
// Some languages are simply not translated
// Example: "az" (Azerbaijani) has no translation in "af" (Afrikaans)
if (!$langName) {
continue;
}
// "af" (Afrikaans) has no "Scripts" block
if (!$langBundle->get('Scripts')) {
continue;
示例4: getAllVariants
/**
* Gets the variants for the input locale
*
* @return array A list of all variants subtag for the locale or NULL if not present
*/
public function getAllVariants()
{
return IntlLocale::getAllVariants($this->getLocale());
}