当我将国家/地区保存到我的数据库中时,我使用国际缩写。
如何将此缩写转换zend_locale
为完整的国家名称?
当我将国家/地区保存到我的数据库中时,我使用国际缩写。
如何将此缩写转换zend_locale
为完整的国家名称?
这是方法。它会尝试使用浏览器的区域设置,如果失败则默认为美国英语。
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']);
您可以使用自intl
PHP 5.3.0 起捆绑的扩展中的功能,或作为 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
Россия
使用Zend_Locale::getTranslationList()
或Zend_Locale::getTranslation()
。请参阅手册中的示例 #7。