phpzend-frameworkinternationalizationzend-locale

Strategy for storing and displaying form dropdown data for provinces, states, prefixes?


I'm currently migrating from a class that stores lists of countries, states & provinces in the form of arrays to using Zend's Locale data in the form of ldml xml files. These ldml files provide localised lists of countries, currencies, languages - so I'm not exactly sure where I should store US States, ( Canadian Provinces ), Prefixes - I was thinking possibly just create a generic xml file and store it in the same directory as the ldml files, but having doubts because it wouldn't really be localised as I'd store it in English.

Should I go with storing it in a generic xml file, or possibly update each of the locale files ( eg en.xml ) and append them? The latter is probably not worth the work, which is why I'm swaying towards just a general.xml or dropdown-data.xml.

As for generating dropdown options, I suppose I could just say, grab all US states, append the array with Canadian provinces, and append that with an 'Other' option - does this seem like the right way to go about?


Solution

  • I ran into this issue also. I use a mixture of Zend_Locale and a custom xml file.

    Zend_Locale is used to generate the country list:

    $locale = new Zend_Locale(Zend_Locale::BROWSER);
    $countries = $locale->getTranslationList('Territory', Zend_Locale::BROWSER, 2);
    asort($countries, SORT_LOCALE_STRING);
    // unset invalid countries
    unset($countries['SU'], $countries['ZZ'], $countries['IM'], $countries['JE'], $countries['VD']);
    

    Then my custom XML file looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <countries>
      <AD>
        <region>Andorra</region>
        <region>Parròquia de Canillo</region>
        <region>Parròquia d'Encamp</region>
        <region>Parròquia de la Massana</region>
    

    Where each child element of <countries> is a 2 letter country code corresponding to the key value of $countries. I then use ajax/php/xpath to repopulate the state/province drop down any time the country drop down value is changed.

    Feel free to download my XML file here: http://gregan.org/provinces.xml I don't remember where I got the original data, nor do I guarantee it's validity