Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Country name with zend locale

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?

like image 825
G. De Wilde Avatar asked Jan 20 '23 22:01

G. De Wilde


1 Answers

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']);
like image 154
Mark Avatar answered Jan 27 '23 17:01

Mark