4

When I save countries into my database I use the international abbreviation.

How do I convert this abbreviation with zend_locale to the full country name?

ajreal
  • 46,720
  • 11
  • 89
  • 119
G. De Wilde
  • 43
  • 1
  • 4
  • you can do that bu using extra table that map between both : http://27.org/isocountrylist/iso_country_list.sql – tawfekov Dec 12 '10 at 04:38

3 Answers3

5

Here is the method. It tries to use the browser's locale and defaults to US English if that fails.

try {
    $locale = new Zend_Locale(Zend_Locale::BROWSER);
    $countries = $locale->getTranslationList('Territory', Zend_Locale::BROWSER, 2);
} catch (exception $e) {
    $locale = new Zend_Locale('en_US');
    $countries = $locale->getTranslationList('Territory', 'en_US', 2);
}

asort($countries, SORT_LOCALE_STRING);

// Unset invalid countries
// SU = USSR
// ZZ = Unknown or Invalid Region
// VD = North Vietnam
// DD = East Germany
unset($countries['SU'], $countries['ZZ'], $countries['VD'], $countries['DD']);
Mark
  • 6,254
  • 1
  • 32
  • 31
3

You can use functionality from the intl extension which is bundled as of PHP 5.3.0, or as a PECL extension as of PHP 5.2.0.

To display a region using a locale:

<?php
print \Locale::getDisplayRegion('da_DK') . "\n";
print \Locale::getDisplayRegion('en_US') . "\n";
print \Locale::getDisplayRegion('ru_RU', 'ru_RU') . "\n";
?>

Will output:

Denmark
United States
Россия

http://php.net/manual/en/locale.getdisplayregion.php

Frederik Krautwald
  • 1,782
  • 23
  • 32
1

Use Zend_Locale::getTranslationList() or Zend_Locale::getTranslation(). See example #7 in the manual.

bgondy
  • 1,198
  • 3
  • 20
  • 32
rik
  • 8,592
  • 1
  • 26
  • 21