4

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

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

4

3 回答 3

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']);
于 2010-12-14T16:03:03.573 回答
3

您可以使用自intlPHP 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
Россия

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

于 2013-01-03T08:11:52.560 回答
1

使用Zend_Locale::getTranslationList()Zend_Locale::getTranslation()。请参阅手册中的示例 #7

于 2010-12-12T05:18:44.030 回答