babel.localedata package¶
Module contents¶
babel.localedata¶
Low-level locale data access.
| note: | The Locale class, which uses this module under the hood, provides a more convenient interface for accessing the locale data. |
|---|---|
| copyright: |
|
| license: | BSD, see LICENSE for more details. |
-
class
babel.localedata.Alias(keys)[source]¶ Bases:
objectRepresentation of an alias in the locale data.
An alias is a value that refers to some other part of the locale data, as specified by the keys.
-
class
babel.localedata.LocaleDataDict(data, base=None)[source]¶ Bases:
_abcoll.MutableMappingDictionary wrapper that automatically resolves aliases to the actual values.
-
babel.localedata.exists(name)[source]¶ Check whether locale data is available for the given locale. Ther return value is True if it exists, False otherwise.
Parameters: name – the locale identifier string
-
babel.localedata.load(name, merge_inherited=True)[source]¶ Load the locale data for the given locale.
The locale data is a dictionary that contains much of the data defined by the Common Locale Data Repository (CLDR). This data is stored as a collection of pickle files inside the
babelpackage.>>> d = load('en_US') >>> d['languages']['sv'] u'Swedish'
Note that the results are cached, and subsequent requests for the same locale return the same dictionary:
>>> d1 = load('en_US') >>> d2 = load('en_US') >>> d1 is d2 True
Parameters: - name – the locale identifier string (or “root”)
- merge_inherited – whether the inherited data should be merged into the data of the requested locale
Raises IOError: if no locale data file is found for the given locale identifer, or one of the locales it inherits from
-
babel.localedata.locale_identifiers()[source]¶ Return a list of all locale identifiers for which locale data is available.
New in version 0.8.1.
Returns: a list of locale identifiers (strings)
-
babel.localedata.merge(dict1, dict2)[source]¶ Merge the data from dict2 into the dict1 dictionary, making copies of nested dictionaries.
>>> d = {1: 'foo', 3: 'baz'} >>> merge(d, {1: 'Foo', 2: 'Bar'}) >>> items = d.items(); items.sort(); items [(1, 'Foo'), (2, 'Bar'), (3, 'baz')]
Parameters: - dict1 – the dictionary to merge into
- dict2 – the dictionary containing the data that should be merged