zend语言环境的国家名称

时间:2010-12-11 23:21:03

标签: php zend-framework internationalization zend-locale

当我将国家/地区保存到我的数据库中时,我使用的是国际缩写。

如何将此缩写与zend_locale转换为完整的国家/地区名称?

3 个答案:

答案 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
Россия

http://php.net/manual/en/locale.getdisplayregion.php

答案 2 :(得分:1)

使用Zend_Locale::getTranslationList()Zend_Locale::getTranslation()。请参阅example #7 in the manual