Skip to content

core: Add get_official_territories() - #1328

Open
ChrisJr404 wants to merge 1 commit into
python-babel:masterfrom
ChrisJr404:get-official-territories
Open

ChrisJr404 wants to merge 1 commit into
python-babel:masterfrom
ChrisJr404:get-official-territories

Conversation

@ChrisJr404

Copy link
Copy Markdown

Closes #904.

Adds get_official_territories() to babel.core, returning a frozenset of the ISO 3166-1 alpha-2 territory codes. As mentioned in the issue, the data is pulled from the CLDR supplemental code mappings during the import, so it isn't a strict copy of the ISO list. I keep the two-letter codes that have a numeric ISO code, and drop the deprecated aliases and the user-assigned ranges, which lands on 250 codes.

A couple of territories the CLDR doesn't carry are missing, and a few exceptionally reserved codes like EU come along, so the docstring calls that out.

@akx akx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of territories the CLDR doesn't carry are missing, and a few exceptionally reserved codes like EU come along, so the docstring calls that out.

This seems unacceptable if the intent is to provide the official ISO 3166-1 territory list. If this were called get_cldr_territories(), that'd be much better already.

However, then I'd like that this was Refs #904, not fixes.

Comment thread scripts/import_cldr.py
Comment on lines +101 to +104
def _is_user_assigned_territory(code):
# ISO 3166-1 reserves these code ranges for private use, so they never
# denote an actual territory.
return code in ('AA', 'ZZ') or 'QM' <= code <= 'QZ' or 'XA' <= code <= 'XZ'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which ones of these appear in the CLDR, I'm curious?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide a list of current ISO 3166 country codes?

2 participants