当我将国家/地区保存到我的数据库中时,我使用的是国际缩写。
如何将此缩写与zend_locale
转换为完整的国家/地区名称?
答案 0 :(得分:5)
这是方法。它尝试使用浏览器的语言环境,如果失败则默认使用美国英语。
try {
$locale = new Zend_Locale(Zend_Locale::BROWSER);
$countries = $locale->getTranslationList('Territory', Zend_Locale::BROWSER, 2);
} catch (exception $e) {
$locale = new Zend_Locale('en_US');
$countries = $locale->getTranslationList('Territory', 'en_US', 2);
}
asort($countries, SORT_LOCALE_STRING);
// Unset invalid countries
// SU = USSR
// ZZ = Unknown or Invalid Region
// VD = North Vietnam
// DD = East Germany
unset($countries['SU'], $countries['ZZ'], $countries['VD'], $countries['DD']);
答案 1 :(得分:3)
您可以使用自PHP 5.3.0开始捆绑的intl
扩展程序中的功能,或者使用PHP 5.2.0中的PECL扩展程序。
使用区域设置显示区域:
<?php
print \Locale::getDisplayRegion('da_DK') . "\n";
print \Locale::getDisplayRegion('en_US') . "\n";
print \Locale::getDisplayRegion('ru_RU', 'ru_RU') . "\n";
?>
将输出:
Denmark
United States
Россия
答案 2 :(得分:1)
使用Zend_Locale::getTranslationList()
或Zend_Locale::getTranslation()
。请参阅example #7 in the manual。