module documentation

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: (c) 2013-2023 by the Babel Team. :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
def exists(name: str) -> bool: (source)

Check whether locale data is available for the given locale. Returns `True` if it exists, `False` otherwise. :param name: the locale identifier string

def load(name: os.PathLike[str]|str, merge_inherited: bool = True) -> dict[str, Any]: (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 ``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 :param name: the locale identifier string (or "root") :param merge_inherited: whether the inherited data should be merged into the data of the requested locale :raise `IOError`: if no locale data file is found for the given locale identifier, or one of the locales it inherits from

@lru_cache(maxsize=None)
def locale_identifiers() -> list[str]: (source)

Return a list of all locale identifiers for which locale data is available. This data is cached after the first invocation. You can clear the cache by calling `locale_identifiers.cache_clear()`. .. versionadded:: 0.8.1 :return: a list of locale identifiers (strings)

def merge(dict1: MutableMapping[Any, Any], dict2: Mapping[Any, Any]): (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'}) >>> sorted(d.items()) [(1, 'Foo'), (2, 'Bar'), (3, 'baz')] :param dict1: the dictionary to merge into :param dict2: the dictionary containing the data that should be merged

def normalize_locale(name: str) -> str|None: (source)

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: os.PathLike[str]|str) -> str: (source)

Resolve a locale identifier to a `.dat` path on disk.

Undocumented

_cache_lock = (source)

Undocumented

_dirname = (source)

Undocumented

_windows_reserved_name_re = (source)

Undocumented