我将如何使用php-intl将国家/地区代码转换为本地化的国家/地区名称 [英] How would I use php-intl to convert country codes to localized country names

查看:328
本文介绍了我将如何使用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'

这篇关于我将如何使用php-intl将国家/地区代码转换为本地化的国家/地区名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆