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?
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?
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']);
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
Россия
Use Zend_Locale::getTranslationList()
or Zend_Locale::getTranslation()
. See example #7 in the manual.