2

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.

Fleshgrinder
  • 15,703
  • 4
  • 47
  • 56
bas
  • 628
  • 9
  • 22

1 Answers1

8

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'

Pieter
  • 1,764
  • 1
  • 12
  • 16
marcosdsanchez
  • 2,529
  • 2
  • 17
  • 20