【问题标题】:How would I use php-intl to convert country codes to localized country names我将如何使用 php-intl 将国家代码转换为本地化国家名称
【发布时间】:2012-09-12 23:46:51
【问题描述】:

您好,我需要根据 PHP 中的国家代码和语言环境检索完整的国家名称。由于 php-intl 现在应该能够做到这一点,我想使用它。

nl_NL
nl -> Nederland
uk -> Verenigd Koninkrijk

en_UK
nl -> The Netherlands
uk -> United Kindom

认为我需要以某种方式使用 php-intl 资源包,但找不到任何有用的示例。

【问题讨论】:

标签: php translation icu intl


【解决方案1】:

没错。 intl 方法可以帮助您。

你需要使用Locale::getDisplayRegion

面向对象的风格:

static string Locale::getDisplayRegion ( string $locale [, string $in_locale ] )

程序风格:

string locale_get_display_region ( string $locale [, string $in_locale ] )

返回输入区域设置区域的适当本地化显示名称。如果为 NULL,则使用默认语言环境。

所以,在你的情况下:

php > echo Locale::getDisplayRegion('nl_NL', 'nl_NL');
Nederland
php > echo Locale::getDisplayRegion('en_GB', 'nl_NL');
Verenigd Koninkrijk
php > echo Locale::getDisplayRegion('nl_NL', 'en_GB');
Netherlands
php > echo Locale::getDisplayRegion('en_GB', 'en_GB');
United Kingdom

请记住,“GB”用于表示英国,而不是“UK”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多