]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
parse_locale(): upper-case variant tag to match file system
authorAarni Koskela <akx@iki.fi>
Tue, 25 Jan 2022 13:14:22 +0000 (15:14 +0200)
committerAarni Koskela <akx@iki.fi>
Thu, 27 Jan 2022 13:23:23 +0000 (15:23 +0200)
   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

babel/core.py
tests/test_core.py

index afc1cb62b1bceb1dd41d037963ca85a40f0b5348..fe5309004ab0f81ac361751fdca8bd7510d9b7d1 100644 (file)
@@ -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)
index 2aa8403c8bb8e355b7daca3484dad0a7adcd6c96..53578f81f6efb4a7b7a6d1fa47dda7500d7e7f93 100644 (file)
@@ -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à)'