From: Armin Ronacher Date: Wed, 24 Jul 2013 19:08:41 +0000 (+0200) Subject: Fixed a bug in the subtag resolving X-Git-Tag: 1.0~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72e2adf123dda49938c6fc6ca2de46f24e6aa046;p=thirdparty%2Fbabel.git Fixed a bug in the subtag resolving --- diff --git a/babel/core.py b/babel/core.py index e5fe4bd0..92a2f4fd 100644 --- a/babel/core.py +++ b/babel/core.py @@ -208,7 +208,12 @@ class Locale(object): Locale('de', territory='DE') This also can perform resolving of likely subtags which it does - by default. + by default. This is for instance useful to figure out the most + likely locale for a territory you can use ``'und'`` as the + language tag: + + >>> Locale.parse('und_AT') + Locale('de', territory='AT') :param identifier: the locale identifier string :param sep: optional component separator @@ -291,11 +296,10 @@ class Locale(object): return locale # Now try without script and variant - lcoale = _try_load(parts2[:2]) + locale = _try_load(parts2[:2]) if locale is not None: return locale - # Give up. raise UnknownLocaleError(input_id) def __eq__(self, other): diff --git a/tests/test_core.py b/tests/test_core.py index 7e13bf6b..ccc30fa6 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -97,6 +97,10 @@ class TestLocaleClass: assert l.territory == 'TW' assert l.script == 'Hant' + l = Locale.parse('und_AT') + assert l.language == 'de' + assert l.territory == 'AT' + def test_get_display_name(self): zh_CN = Locale('zh', 'CN', script='Hans') assert zh_CN.get_display_name('en') == 'Chinese (Simplified, China)'