You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide a list of current ISO 3166 country codes? #904
More of a feature question/suggestion: would it be possible to generate and provide a list of ISO 3166-2 country codes? Quick glance at common/main/*.xml (cldr-common.zip) would indicate that the 2-letter codes are provided as
Thanks @akx, happy to create a PR if you don’t mind a little guidance:
I think a list[str] would suffice, which then contains the two-letter country codes?
Should that list live in babel.core next to the LOCALE_ALIASES, maybe called COUNTRIES or… ?
Within the CLDR data, should I work from the XML as noted above, or off of the filenames in common/main/*.xml (you’re more familiar with the CLDR data than I am).
Sure, just a frozenset of ISO 3166-2s should be fine to begin with, I think? (A list is needlessly ordered.)
It shouldn't be hard-coded (in fact LOCALE_ALIASES probably shouldn't be either), especially since you'd load it from the CLDR. The API would probably be get_iso3166_2_country_codes() or similar, and it would call get_global() to load the data from the pickle files.
The filenames are locale identifiers, not countries. If there is a definitive list of countries within the CLDR data (I don't have a browsable copy at hand right now), then use that by all means.
Yes, to format the data to be pickled into global.dat, and babel/core.py.
Sure, just a frozenset of ISO 3166-2s should be fine to begin with, I think? (A list is needlessly ordered.)
…and performs worse when searched. You just beat me to making the change from list[str] to set[str], but frozenset works as well 👍🏼
It shouldn't be hard-coded (in fact LOCALE_ALIASES probably shouldn't be either), especially since you'd load it from the CLDR. The API would probably be get_iso3166_2_country_codes() or similar, and it would call get_global() to load the data from the pickle files.
Thanks!
The filenames are locale identifiers, not countries. If there is a definitive list of countries within the CLDR data (I don't have a browsable copy at hand right now), then use that by all means.
I’ve not found a list of country codes, but thought that iterating over the main/*.xml files and pulling out their ldml/identity/language/@type values — which should be the country codes.
Yes, to format the data to be pickled into global.dat, and babel/core.py.
Now, let cldr_set be the set of territory codes extracted from the CLDR and let iso_set be the set of country codes extracted from the ISO page (which is the same as the set extracted from Wikipedia) then:
So maybe this is not such a good idea because the CLDR might not contain a complete list of ISO 3166 country codes, but I’m not familiar enough with it to be certain.
I wonder if the ISO folks would donate their Country Codes for the purpose of building this package? Or I’d add some code to scrape the Wikipedia page.
Scraping the Wikipedia page during the import process sounds like a bad idea, and dealing with ISO to license the country codes for use in Babel also sounds problematic. :(
That said, we're no strangers to the CLDR containing partial data, and the codes that show up in those difference lists are all "special" somehow:
AQ: Antarctica
BV: Bouvet Island (belongs to Norway)
DG: exceptional reservation for Diego Garcia (Reserved on request of ITU for location of certain telecommunications installations)
EA: exceptional reservation for Ceuta, Melilla (part of Spain) (Reserved on request of WCO for area not covered by European Union Customs arrangements)
GS: South Georgia and the South Sandwich Islands (British Overseas Territory)
HM: Heard Island and McDonald Islands (belongs to Australia)
IC: exceptional reservation for Canary Islands (part of Spain) (Reserved on request of WCO for area not covered by European Union Customs arrangements)
TF: French Southern Territories (Covers the French Southern and Antarctic Lands except Adélie Land)
XK: being used by the European Commission, the IMF, and SWIFT, the CLDR, and other organizations as a temporary country code for Kosovo.
I don't think it's that big of a problem if those do or don't necessarily appear in the CLDR-derived data...
Scraping the Wikipedia page during the import process sounds like a bad idea, and dealing with ISO to license the country codes for use in Babel also sounds problematic. :(
What I can do is file an issue with a license request, and just ask if we’d use parts of their data to generate this package. What says you? I filed issue #45.
That said, we're no strangers to the CLDR containing partial data, and the codes that show up in those difference lists are all "special" somehow:
[…]
I don't think it's that big of a problem if those do or don't necessarily appear in the CLDR-derived data...
How about his: if we can’t use the data from the Debian repo then I’ll proceed with the CLDR set alone. We could manually add the missing countries (though I feel a little naughty about manual intervention on generated data).
@jenstroeger obviously your prerogative to work on this. However, it makes your life any easier. There is pycountry which also sources it's ISO 3166 data from debian's iso-codes.
>>>importpycountry>>>len(pycountry.countries)
249>>>list(pycountry.countries)[0]
Country(alpha_2='AF', alpha_3='AFG', name='Afghanistan', numeric='004', official_name='Islamic Republic of Afghanistan')
Activity
akx commentedon Sep 13, 2022
Sounds like a good idea. If you feel like writing a PR to implement this, feel free to!
jenstroeger commentedon Sep 13, 2022
Thanks @akx, happy to create a PR if you don’t mind a little guidance:
list[str]would suffice, which then contains the two-letter country codes?babel.corenext to theLOCALE_ALIASES, maybe calledCOUNTRIESor… ?common/main/*.xml(you’re more familiar with the CLDR data than I am).akx commentedon Sep 13, 2022
LOCALE_ALIASESprobably shouldn't be either), especially since you'd load it from the CLDR. The API would probably beget_iso3166_2_country_codes()or similar, and it would callget_global()to load the data from the pickle files.global.dat, andbabel/core.py.jenstroeger commentedon Sep 13, 2022
…and performs worse when searched. You just beat me to making the change from
list[str]toset[str], but frozenset works as well 👍🏼Thanks!
I’ve not found a list of country codes, but thought that iterating over the
main/*.xmlfiles and pulling out theirldml/identity/language/@typevalues — which should be the country codes.Thanks!
jenstroeger commentedon Sep 18, 2022
I think using
ldml/identity/territory/@type(from files inmain/*.xml) doesn’t work.For reference, I downloaded ISO_3166-1_alpha-2.html from Wikipedia and extracted the set of “Officially assigned” country codes
which returns 249 elements:
To crosscheck, I saved the page DOM from the iso.org website and extracted country codes from that table:
which returned the exact same result. That set is our baseline.
Next, I hooked into this CLDR import fragment:
babel/scripts/import_cldr.py
Lines 375 to 381 in 33d1dd7
to get to all territory codes used in the CLDR:
This results in 248 territory codes:
Now, let
cldr_setbe the set of territory codes extracted from the CLDR and letiso_setbe the set of country codes extracted from the ISO page (which is the same as the set extracted from Wikipedia) then:So maybe this is not such a good idea because the CLDR might not contain a complete list of ISO 3166 country codes, but I’m not familiar enough with it to be certain.
I wonder if the ISO folks would donate their Country Codes for the purpose of building this package? Or I’d add some code to scrape the Wikipedia page.
@akx, what do you think?
akx commentedon Sep 20, 2022
Scraping the Wikipedia page during the import process sounds like a bad idea, and dealing with ISO to license the country codes for use in Babel also sounds problematic. :(
The
isocodesproject uses https://salsa.debian.org/iso-codes-team/iso-codes/-/blob/main/data/iso_3166-1.json as a source. The license there is LGPL (IANAL and all, it's hard to say whether the static data (or derivatives thereof) is/could be licensed under the LGPL).That said, we're no strangers to the CLDR containing partial data, and the codes that show up in those difference lists are all "special" somehow:
I don't think it's that big of a problem if those do or don't necessarily appear in the CLDR-derived data...
jenstroeger commentedon Sep 20, 2022
I agree very much 😉
Oh that’s a useful repo indeed, I didn’t know!
What I can do is file an issue with a license request, and just ask if we’d use parts of their data to generate this package. What says you?I filed issue #45.How about his: if we can’t use the data from the Debian repo then I’ll proceed with the CLDR set alone. We could manually add the missing countries (though I feel a little naughty about manual intervention on generated data).
akx commentedon Sep 26, 2022
I'm not against that, but I'm a bit on the fence against adding another data source to the import process.
Maybe we should start with the CLDR data, with a note that "some territories may be missing if they are not present in the CLDR data"...?
jenstroeger commentedon Nov 15, 2022
@akx still no response to issue #45. Shall I proceed with:
HIRANO-Satoshi commentedon Jan 18, 2023
@jenstroeger ping, ping, ping
Here is a list of territories. Look at .
https://raw.githubusercontent.com/unicode-org/cldr/main/common/main/en.xml
A JSON version is here.
https://github.com/unicode-org/cldr-json/blob/main/cldr-json/cldr-localenames-full/main/en/territories.json
Keys with numbers, UE, EZ, UN, XA, XB, UN-alt-short should be removed.
Atem18 commentedon Sep 1, 2023
Hi, I have put the project as LGPL because I thought that I had to put the same licence as the original project.
But maybe I do not need : https://opensource.stackexchange.com/questions/5175/including-untouched-lgpl-library-in-a-mit-licenced-project#:~:text=Yes.%20Your%20only%20LGPL%20requirements%20apply%20to%20the,would%20then%20use%20some%20of%20the%20library%27s%20classes.
So if someone can really confirm, I can change the licence.
nschimmoller commentedon Dec 19, 2023
@jenstroeger obviously your prerogative to work on this. However, it makes your life any easier. There is pycountry which also sources it's ISO 3166 data from debian's iso-codes.
jenstroeger commentedon Dec 20, 2023
Hot diggity, I had lost track of this issue, my apologies!
I need to make time this week to noodle on this and a couple of other OSS Github PRs.