diff options
author | Aarni Koskela <akx@iki.fi> | 2022-01-25 15:14:22 +0200 |
---|---|---|
committer | Aarni Koskela <akx@iki.fi> | 2022-01-27 15:23:23 +0200 |
commit | 8bbaa65826843391f97605bbde5c0f0a6105fd1e (patch) | |
tree | ac3cfc45d45c94b6efc923e1740ede200b0eb3ad | |
parent | 5279170b51de43a48d3a2505eb12399c81112d8a (diff) | |
download | babel-8bbaa65826843391f97605bbde5c0f0a6105fd1e.tar.gz |
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
-rw-r--r-- | babel/core.py | 8 | ||||
-rw-r--r-- | tests/test_core.py | 6 |
2 files changed, 13 insertions, 1 deletions
diff --git a/babel/core.py b/babel/core.py index afc1cb6..fe53090 100644 --- a/babel/core.py +++ b/babel/core.py @@ -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: @@ -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) diff --git a/tests/test_core.py b/tests/test_core.py index 2aa8403..53578f8 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -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à)' |