I’m currently working on adding an address form to Keila. Unfortunately, address forms can be wildly different from country to country. Do they require a postal code? Does the postal code go before or after the locality/city name? On top of that, certain labels for common address fields need to be different between countries (e.g. the relevant administrative region in address is called a state in Mexico but a province in Canada. Postal codes are called Postcode in the UK but ZIP Code in the US.)
Is there an actively maintained Elixir library that offers data on international address formats and these localizations? Here are the libraries I have found so far:
countries: Not updated since 2019, doesn’t seem to have any data on address formats
countriex: Not updated since 2017, has no documentation
ex_countries: Actively maintained, doesn’t have data on address formats.
ex_cldr + ex_cldr_territories (friendly ping @kip & @schultzer): Actively maintained, provides all the necessary data to offer dropdowns for the country, including translations of country subdivisions. None of the cldr libraries seem to have any data on address formatting, however. There also doesn’t seem to be data on what the country subdivisions are called (province, state, etc).
Outside the BEAM universe, there is the PHP addressing library which includes most of the data I’m looking for, including address formats (there’s also a Ruby port). The one thing that’s also missing here is country-specific i18n for the various address fields.
What do you all usually do when you need to build an international address form? Did I miss any Elixir resources?
To illustrate what I eventually want to achieve, here are two address forms for Germany and Brazil respectively, built based on the data from the PHP addressing library:
Sounds like they source their data from cdlr based on their last commit. ex_cldr | Hex exists to pull the database, so we might just lack a companion library exposing the relevant data in a useful way.
I don’t think the postal address format is part of CLDR. That seems to come from some sort of Google API.
Edit: This is where the address format data is coming from: https://chromium-i18n.appspot.com/ssl-address
Even within a country, the way fields are presented will vary.
Given name and family name are not enough. In some cases people will want to select a title, and depending on their culture should you use the title with only the family name or the full name? Should the family name be printed before or after the given name? Some people don’t have last names, etc.
For these reasons it is sometimes more practical to have a full name field, though it has its downsides.
Good point. The data from Google doesn’t account for titles (and I don’t care for them either, tbh) but they do change the order of family name and given name, e.g. for Vietnam or China, family name comes first. Generally, mononyms seem to be very unommon, so I’m also not particularly concerned about that either.
We definitely could use a library built on top, but you would have to make some decisions on which standard to use. From a cursory search it seams like Oasis is not the only one out there.
The times when I have had to capture this kind of information has always been for identification purposes and not shipping which is an entirely more complex problem. For identification you can usually get away with a minimal setup: country, subdivision, postal code, city, address_2, address_1, name.
Looking forward to see where this is going! And let me know if you have any questions around the CLDR dataset.