package documentation

Locale utilities.

From __init__.py:

Function get_translation Get a translation function based on the *catalog* and *namespace*.
Function get_translator 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_console Initialize locale for console.
Function is_translator_registered Undocumented
Function setlocale Update locale settings.
Variable __ Undocumented
Variable admonitionlabels Undocumented
Variable pairindextypes Undocumented
Variable translators Undocumented
Variable versionlabels Undocumented
Class _TranslationProxy Class for proxy strings from gettext translations. This is a helper for the lazy_* functions from this module.
Function _lazy_translate Used instead of _ when creating TranslationProxy, because _ is not bound yet at that time.
Constant _LOCALE_DIR Undocumented
Variable _ Undocumented

Undocumented

def init(locale_dirs, language, catalog='sphinx', namespace='general'): (source)

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
locale_dirs:List[Optional[str]]Undocumented
language:Optional[str]Undocumented
catalog:strUndocumented
namespace:strUndocumented
Returns
Tuple[NullTranslations, bool]Undocumented
def setlocale(category, value=None): (source)

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:intUndocumented
value:Union[str, Iterable[str], None]Undocumented
_LOCALE_DIR = (source)

Undocumented

Value
path.abspath(path.dirname(__file__))
def init_console(locale_dir=_LOCALE_DIR, catalog='sphinx'): (source)

Initialize locale for console. .. versionadded:: 1.8

Parameters
locale_dir:strUndocumented
catalog:strUndocumented
Returns
Tuple[NullTranslations, bool]Undocumented
def get_translator(catalog='sphinx', namespace='general'): (source)

Undocumented

Parameters
catalog:strUndocumented
namespace:strUndocumented
Returns
NullTranslationsUndocumented
def is_translator_registered(catalog='sphinx', namespace='general'): (source)

Undocumented

Parameters
catalog:strUndocumented
namespace:strUndocumented
Returns
boolUndocumented
def _lazy_translate(catalog, namespace, message): (source)

Used instead of _ when creating TranslationProxy, because _ is not bound yet at that time.

Parameters
catalog:strUndocumented
namespace:strUndocumented
message:strUndocumented
Returns
strUndocumented
def get_translation(catalog, namespace='general'): (source)

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:strUndocumented
namespace:strUndocumented
Returns
Callable[[str], str]Undocumented

Undocumented

Undocumented

admonitionlabels = (source)

Undocumented

versionlabels: Dict[str, str] = (source)

Undocumented

pairindextypes: Dict[str, str] = (source)

Undocumented