且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我将如何使用php-intl将国家/地区代码转换为本地化的国家/地区名称

更新时间:2023-08-17 17:53:04

完全正确. intl方法可以帮助您.

Exactly. The intl methods can help you with that.

您需要使用 Locale :: getDisplayRegion

面向对象的样式:

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

程序样式:

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

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

Returns an appropriately localized display name for region of the input locale. If is NULL then the default locale is used.

因此,在您的情况下:

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'

Remember that 'GB' is used for the United Kingdom instead of 'UK'