Question

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

I think I need to use php-intl resource bundles somehow, but am unable to find any useful examples.

Was it helpful?

Solution

Exactly. The intl methods can help you with that.

You need to use Locale::getDisplayRegion

Object oriented style:

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

Procedural style:

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

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

So, in your case:

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top