summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2013-07-28 23:15:59 +0200
committerArmin Ronacher <armin.ronacher@active-4.com>2013-07-28 23:15:59 +0200
commite6cdac96de420ed9c556f810b40a38c69fba0836 (patch)
tree23f55b7a77864e03b7f88b8e077fe1367b107900
parente274ac505e9c2fddaca27a9798bda483c5b6632c (diff)
parent4117268d15375da88cbe86da873133c67493a982 (diff)
downloadbabel-e6cdac96de420ed9c556f810b40a38c69fba0836.tar.gz
Merge branch '1.x-maintenance'
-rw-r--r--CHANGES9
-rw-r--r--babel/core.py40
-rw-r--r--tests/test_core.py5
3 files changed, 39 insertions, 15 deletions
diff --git a/CHANGES b/CHANGES
index 08bbe2a..66202f2 100644
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,15 @@ Version 2.0
(release date to be decided, codename to be selected)
+Version 1.3
+-----------
+
+(bugfix release, release date to be decided)
+
+- Fixed a bug in likely-subtag resolving for some common locales.
+ This primarily makes ``zh_CN`` work again which was broken
+ due to how it was defined in the likely subtags combined with
+ our broken resolving. This fixes #37.
Version 1.2
-----------
diff --git a/babel/core.py b/babel/core.py
index 6b9cd41..6e6e6d6 100644
--- a/babel/core.py
+++ b/babel/core.py
@@ -248,7 +248,6 @@ class Locale(object):
raise TypeError('Unxpected value for identifier: %r' % (identifier,))
parts = parse_locale(identifier, sep=sep)
-
input_id = get_locale_identifier(parts)
def _try_load(parts):
@@ -257,6 +256,17 @@ class Locale(object):
except UnknownLocaleError:
return None
+ def _try_load_reducing(parts):
+ # Success on first hit, return it.
+ locale = _try_load(parts)
+ if locale is not None:
+ return locale
+
+ # Now try without script and variant
+ locale = _try_load(parts[:2])
+ if locale is not None:
+ return locale
+
locale = _try_load(parts)
if locale is not None:
return locale
@@ -283,22 +293,22 @@ class Locale(object):
parts = language, territory, script, variant
+ # First match: try the whole identifier
new_id = get_locale_identifier(parts)
likely_subtag = get_global('likely_subtags').get(new_id)
- if likely_subtag is None:
- raise UnknownLocaleError(input_id)
-
- parts2 = parse_locale(likely_subtag)
-
- # Success on first hit, return it.
- locale = _try_load(parts2)
- if locale is not None:
- return locale
-
- # Now try without script and variant
- locale = _try_load(parts2[:2])
- if locale is not None:
- return locale
+ if likely_subtag is not None:
+ locale = _try_load_reducing(parse_locale(likely_subtag))
+ if locale is not None:
+ return locale
+
+ # If we did not find anything so far, try again with a
+ # simplified identifier that is just the language
+ likely_subtag = get_global('likely_subtags').get(language)
+ if likely_subtag is not None:
+ language2, _, script2, variant2 = parse_locale(likely_subtag)
+ locale = _try_load_reducing((language2, territory, script2, variant2))
+ if locale is not None:
+ return locale
raise UnknownLocaleError(input_id)
diff --git a/tests/test_core.py b/tests/test_core.py
index ccc30fa..1605159 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -97,6 +97,11 @@ class TestLocaleClass:
assert l.territory == 'TW'
assert l.script == 'Hant'
+ l = Locale.parse('zh_CN')
+ assert l.language == 'zh'
+ assert l.territory == 'CN'
+ assert l.script == 'Hans'
+
l = Locale.parse('und_AT')
assert l.language == 'de'
assert l.territory == 'AT'