module documentation

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
  1. 2013-2021 by the Babel Team.
Unknown Field: license
BSD, see LICENSE for more details.
Class ​Alias Representation of an alias in the locale data.
Class ​Locale​Data​Dict 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
def exists(name):

Check whether locale data is available for the given locale.

Returns True if it exists, False otherwise.

Parameters
namethe locale identifier string
def load(name, merge_inherited=True):

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
namethe locale identifier string (or "root")
merge​_inheritedwhether the inherited data should be merged into the data of the requested locale
Raises
IOErrorif no locale data file is found for the given locale identifer, or one of the locales it inherits from
def locale_identifiers():

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.

New in version 0.8.1.
Returns
a list of locale identifiers (strings)
def merge(dict1, dict2):

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
dict1the dictionary to merge into
dict2the dictionary containing the data that should be merged
def normalize_locale(name):

Normalize a locale ID by stripping spaces and apply proper casing.

Returns the normalized locale ID string or None if the ID is not recognized.

def resolve_locale_filename(name):
Resolve a locale identifier to a .dat path on disk.
_cache: dict =

Undocumented

_cache_lock =

Undocumented

_dirname =

Undocumented

_windows_reserved_name_re =

Undocumented