我将如何使用php-intl将国家/地区代码转换为本地化的国家/地区名称
您好,我需要根据国家/地区代码和PHP中的语言环境检索完整的国家/地区名称.由于php-intl现在应该可以做到这一点,所以我想使用它.
Hello I need to retrieve full country names based on a country code and a locale in PHP. Since php-intl is now supposed to be able to do this I want to use that.
nl_NL
nl -> Nederland
uk -> Verenigd Koninkrijk
en_UK
nl -> The Netherlands
uk -> United Kindom
我认为我需要以某种方式使用php-intl资源包,但无法找到任何有用的示例.
I think I need to use php-intl resource bundles somehow, but am unable to find any useful examples.
完全正确. 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'