Skip to content

Commit 8bbaa65

Browse files
committed
parse_locale(): upper-case variant tag to match file system
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
1 parent 5279170 commit 8bbaa65

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

babel/core.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,12 @@ def parse_locale(identifier, sep='_'):
10481048
('zh', 'CN', None, None)
10491049
>>> parse_locale('zh_Hans_CN')
10501050
('zh', 'CN', 'Hans', None)
1051+
>>> parse_locale('ca_es_valencia')
1052+
('ca', 'ES', None, 'VALENCIA')
1053+
>>> parse_locale('en_150')
1054+
('en', '150', None, None)
1055+
>>> parse_locale('en_us_posix')
1056+
('en', 'US', None, 'POSIX')
10511057
10521058
The default component separator is "_", but a different separator can be
10531059
specified using the `sep` parameter:
@@ -1107,7 +1113,7 @@ def parse_locale(identifier, sep='_'):
11071113
if parts:
11081114
if len(parts[0]) == 4 and parts[0][0].isdigit() or \
11091115
len(parts[0]) >= 5 and parts[0][0].isalpha():
1110-
variant = parts.pop()
1116+
variant = parts.pop().upper()
11111117

11121118
if parts:
11131119
raise ValueError('%r is not a valid locale identifier' % identifier)

tests/test_core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,9 @@ def test_issue_601_no_language_name_but_has_variant():
325325
# part of a language name.
326326

327327
assert Locale.parse('fi_FI').get_display_name('kw_GB') == None
328+
329+
330+
def test_issue_814():
331+
loc = Locale.parse('ca_ES_valencia')
332+
assert loc.variant == "VALENCIA"
333+
assert loc.get_display_name() == 'català (Espanya, valencià)'

0 commit comments

Comments
 (0)