phpzend-frameworkinternationalizationzend-locale

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?


Solution

  • 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']);