Locale utilities.
From __init__.py
:
Function | get |
Get a translation function based on the *catalog* and *namespace*. |
Function | get |
Undocumented |
Function | init |
Look for message catalogs in `locale_dirs` and *ensure* that there is at least a NullTranslations catalog set in `translators`. If called multiple times or if several ``.mo`` files are found, their contents are merged together (thus making ``init`` reentrant). |
Function | init |
Initialize locale for console. |
Function | is |
Undocumented |
Function | setlocale |
Update locale settings. |
Variable | __ |
Undocumented |
Variable | admonitionlabels |
Undocumented |
Variable | pairindextypes |
Undocumented |
Variable | translators |
Undocumented |
Variable | versionlabels |
Undocumented |
Class | _ |
Class for proxy strings from gettext translations. This is a helper for the lazy_* functions from this module. |
Function | _lazy |
Used instead of _ when creating TranslationProxy, because _ is not bound yet at that time. |
Constant | _LOCALE |
Undocumented |
Variable | _ |
Undocumented |
Look for message catalogs in `locale_dirs` and *ensure* that there is at least a NullTranslations catalog set in `translators`. If called multiple times or if several ``.mo`` files are found, their contents are merged together (thus making ``init`` reentrant).
Parameters | |
localeList[ | Undocumented |
language:Optional[ | Undocumented |
catalog:str | Undocumented |
namespace:str | Undocumented |
Returns | |
Tuple[ | Undocumented |
Update locale settings. This does not throw any exception even if update fails. This is workaround for Python's bug. For more details: * https://github.com/sphinx-doc/sphinx/issues/5724 * https://bugs.python.org/issue18378#msg215215 .. note:: Only for internal use. Please don't call this method from extensions. This will be removed in Sphinx 6.0.
Parameters | |
category:int | Undocumented |
value:Union[ | Undocumented |
Initialize locale for console. .. versionadded:: 1.8
Parameters | |
localestr | Undocumented |
catalog:str | Undocumented |
Returns | |
Tuple[ | Undocumented |
Undocumented
Parameters | |
catalog:str | Undocumented |
namespace:str | Undocumented |
Returns | |
NullTranslations | Undocumented |
Get a translation function based on the *catalog* and *namespace*. The extension can use this API to translate the messages on the extension:: import os from sphinx.locale import get_translation MESSAGE_CATALOG_NAME = 'myextension' # name of *.pot, *.po and *.mo files _ = get_translation(MESSAGE_CATALOG_NAME) text = _('Hello Sphinx!') def setup(app): package_dir = os.path.abspath(os.path.dirname(__file__)) locale_dir = os.path.join(package_dir, 'locales') app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir) With this code, sphinx searches a message catalog from ``${package_dir}/locales/${language}/LC_MESSAGES/myextension.mo``. The :confval:`language` is used for the searching. .. versionadded:: 1.8
Parameters | |
catalog:str | Undocumented |
namespace:str | Undocumented |
Returns | |
Callable[ | Undocumented |