Skip to content

Commit

Permalink
parse_locale(): upper-case variant tag to match file system
Browse files Browse the repository at this point in the history
   At all times, language tags and their subtags, including private use
   and extensions, are to be treated as case insensitive: there exist
   conventions for the capitalization of some of the subtags, but these
   MUST NOT be taken to carry meaning.

Fixes #814
  • Loading branch information
akx committed Jan 27, 2022
1 parent 5279170 commit 8bbaa65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion babel/core.py
Expand Up @@ -1048,6 +1048,12 @@ def parse_locale(identifier, sep='_'):
('zh', 'CN', None, None)
>>> parse_locale('zh_Hans_CN')
('zh', 'CN', 'Hans', None)
>>> parse_locale('ca_es_valencia')
('ca', 'ES', None, 'VALENCIA')
>>> parse_locale('en_150')
('en', '150', None, None)
>>> parse_locale('en_us_posix')
('en', 'US', None, 'POSIX')
The default component separator is "_", but a different separator can be
specified using the `sep` parameter:
Expand Down Expand Up @@ -1107,7 +1113,7 @@ def parse_locale(identifier, sep='_'):
if parts:
if len(parts[0]) == 4 and parts[0][0].isdigit() or \
len(parts[0]) >= 5 and parts[0][0].isalpha():
variant = parts.pop()
variant = parts.pop().upper()

if parts:
raise ValueError('%r is not a valid locale identifier' % identifier)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_core.py
Expand Up @@ -325,3 +325,9 @@ def test_issue_601_no_language_name_but_has_variant():
# part of a language name.

assert Locale.parse('fi_FI').get_display_name('kw_GB') == None


def test_issue_814():
loc = Locale.parse('ca_ES_valencia')
assert loc.variant == "VALENCIA"
assert loc.get_display_name() == 'català (Espanya, valencià)'

0 comments on commit 8bbaa65

Please sign in to comment.