From: Kevin Deldycke Date: Wed, 2 Mar 2016 16:04:13 +0000 (+0100) Subject: Force normalization of locale ID. X-Git-Tag: 2.3.1~11^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78eea4c158bfcd9f50205c7ffff08130dbb8286f;p=thirdparty%2Fbabel.git Force normalization of locale ID. --- diff --git a/babel/localedata.py b/babel/localedata.py index 437f49fa..a20a8813 100644 --- a/babel/localedata.py +++ b/babel/localedata.py @@ -15,6 +15,7 @@ import os import threading from collections import MutableMapping +from itertools import chain from babel._compat import pickle @@ -24,15 +25,22 @@ _cache_lock = threading.RLock() _dirname = os.path.join(os.path.dirname(__file__), 'locale-data') +def normalize_locale(name): + """Return a normalized locale ID or `None` if the ID is not recognized.""" + name = name.strip().lower() + for locale_id in chain.from_iterable([_cache, locale_identifiers()]): + if name == locale_id.lower(): + return locale_id + + def exists(name): - """Check whether locale data is available for the given locale. Ther - return value is `True` if it exists, `False` otherwise. + """Check whether locale data is available for the given locale. + + Returns `True` if it exists, `False` otherwise. :param name: the locale identifier string """ - if name in _cache: - return True - return os.path.exists(os.path.join(_dirname, '%s.dat' % name)) + return True if normalize_locale(name) else False def locale_identifiers():