default_locale(category=None,
aliases={'ar': 'ar_SY', 'bg': 'bg_BG', 'bs': 'bs_BA', 'ca': 'ca_ES', '...)
Returns the system default locale for a given category, based on
environment variables.
str
negotiate_locale(preferred,
available,
sep='_',
aliases={'ar': 'ar_SY', 'bg': 'bg_BG', 'bs': 'bs_BA', 'ca': 'ca_ES', '...)
Find the best match between available and requested locale strings.
tuple
parse_locale(identifier,
sep='_')
Parse a locale identifier into a tuple of the form:
By default, some web browsers unfortunately do not include the territory
in the locale identifier for many locales, and some don't even allow the
user to easily add the territory. So while you may prefer using qualified
locale identifiers in your web-application, they would not normally match
the language-only locale sent by such browsers. To workaround that, this
function uses a default mapping of commonly used langauge-only locale
identifiers to identifiers including the territory:
Some browsers even use an incorrect or outdated language code, such as "no"
for Norwegian, where the correct locale identifier would actually be "nb_NO"
(Bokmål) or "nn_NO" (Nynorsk). The aliases are intended to take care of
such cases, too:
You can override this default mapping by passing a different aliases
dictionary to this function, or you can bypass the behavior althogher by
setting the aliases parameter to None.
Parameters:
preferred - the list of locale strings preferred by the user
available - the list of locale strings available
sep - character that separates the different parts of the locale
strings
aliases - a dictionary of aliases for locale identifiers
Returns: str
the locale identifier for the best match, or None if no match
was found
parse_locale(identifier,
sep='_')
Parse a locale identifier into a tuple of the form: