Country name with zend locale

When I save countries in my database, I use the international abbreviation.

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

+4
source share
3 answers

Here is the method. It tries to use the browser locale and is used by default for American 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']); 
+5
source

You can use the functionality from the intl extension, which is associated with PHP 5.3.0, or as a PECL extension with 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"; ?> 

It will display:

 Denmark United States  

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

+3
source

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

+1
source

All Articles