dongpao5127 2011-08-10 06:28
浏览 39
已采纳

本地化州/省数据

I am trying to provide drop down menus so that users can select their country and state in a multilingual web application.

I was able to extract a list of countries and the name of those countries in various languages from unicode.org's cldr files.

Currently these are all stored in arrays in seperate files (I have files such as en.php, es.php, fr.php and so on).

While this doesn't seem too difficult, I am having trouble trying to get a list of Administrative Divions (states/provinces/prefectures) in localized form. Essentially, if the person is using the french version (fr_fr) of the application, I would like that when he selects "France" as his country, the states drop down would be populated with the various french departments in french.

I have found some data on geonames.org: http://www.geonames.org/GB/administrative-division-united-kingdom.html but all the content seems to be in English, so I can't provide localized states. Additionally, some countries like the UK have 2 sets of data in "Administrative division", which might make grabbing the data automatically somewhat problematic.

Similiar, if someone is using the Japanese version, then the prefecture drop down should contain the prefectures in Japanese. As for the other countries, I think it would be unfeasible to have all administrative divisions translated into Japanese, so defaulting to English is fine.

Additionally, countries have different terms for administrative divisions (states/territory/provinces/prefectures and perhaps some other ones I have missed. I would like to have this data somewhere, so that when someone selets say, Japan, instead of the label being "state" he is presented with the label "prefecture".

Another issue I have is where to store all the data. At the moment I am leaning towards storing the administrative division (state) and label (state,prefecture, etc) in arrays in a more specific file containing the locale (en_US.php, en_GB.php, etc).

Has anyone dealt with something like this on a project? I would love to hear your suggestions/views. Also, it would be great if someone can provide a source where I can get localized states.

EDIT

  • Post codes: Some countries don't have post codes, so I need to store this information and make sure the postcode isn't required when submitting.
  • Optional states: As mentioned. Some countries don't have states, so this will need to be stored somehow.
  • 写回答

1条回答 默认 最新

  • dougua3705 2011-08-25 04:22
    关注

    What are you using the state/province data for? If it is for mailing, then keep in mind that state/province is not required (and is not typically given) in the mailing addresses of many countries, and you will just annoy the user if you ask for it when it is not needed.

    Postal code is more important for mailing and the Unicode CLDR has the postal code validation regex for 158 countries. (It is in supplemental/postalCodeData.xml when you download the CLDR)

    If you really want state/province, then there is a CLDR proposal to add address formatting information to the CLDR here - http://unicode.org/review/pri180/

    You'll notice that the proposal links to a google appengine service which contains the proposed address formatting information - http://i18napis.appspot.com/address

    The states/provinces seem to be listed there, but only for countries which require such information in postal addresses. And it looks like it is translated into the languages of each country - for example, Canadian province names are listed in both English and french. It also tells you, for example, that it is called a prefecture in Japan

    If you really, really want all subdivisions, regardless of whether it is needed in a postal address, then grab ISO 3166-2. Buy it here - http://www.iso.org/iso/country_codes/iso_3166_databases.htm (you can also potentially scape it off of the wikipedia site for ISO-3166-2)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False