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. | |
Unknown Field: copyright | |
| |
Unknown Field: license | |
BSD, see LICENSE for more details. |
Class | Alias |
Representation of an alias in the locale data. |
Class | LocaleDataDict |
Dictionary wrapper that automatically resolves aliases to the actual values. |
Function | exists |
Check whether locale data is available for the given locale. |
Function | load |
Load the locale data for the given locale. |
Function | locale_identifiers |
Return a list of all locale identifiers for which locale data is available. |
Function | merge |
Merge the data from dict2 into the dict1 dictionary, making copies of nested dictionaries. |
Function | normalize_locale |
Normalize a locale ID by stripping spaces and apply proper casing. |
Function | resolve_locale_filename |
Resolve a locale identifier to a .dat path on disk. |
Variable | _cache |
Undocumented |
Variable | _cache_lock |
Undocumented |
Variable | _dirname |
Undocumented |
Variable | _windows_reserved_name_re |
Undocumented |
Check whether locale data is available for the given locale.
Returns True
if it exists, False
otherwise.
Parameters | |
name | the locale identifier string |
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 babel package.
>>> 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 |
Return a list of all locale identifiers for which locale data is available.
This data is cached after the first invocation in locale_identifiers.cache
.
Removing the locale_identifiers.cache
attribute or setting it to None
will cause this function to re-read the list from disk.
Returns | |
a list of locale identifiers (strings) |
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'}) >>> sorted(d.items()) [(1, 'Foo'), (2, 'Bar'), (3, 'baz')]
Parameters | |
dict1 | the dictionary to merge into |
dict2 | the dictionary containing the data that should be merged |