Locale utilities.
Unknown Field: copyright | |
Copyright 2007-2022 by the Sphinx team, see AUTHORS. | |
Unknown Field: license | |
BSD, see LICENSE for details. |
From __init__.py
:
Function | get_translation |
Get a translation function based on the catalog and namespace. |
Function | init |
No summary |
Function | init_console |
Initialize locale for console. |
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. |
Function | get_translator |
Undocumented |
Function | is_translator_registered |
Undocumented |
Function | setlocale |
Update locale settings. |
Variable | _ |
Undocumented |
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[ | 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:
Note
Only for internal use. Please don't call this method from extensions. This will be removed in future.
Parameters | |
category:int | Undocumented |
value:Union[ | Undocumented |
Initialize locale for console.
Parameters | |
locale_dir:str | Undocumented |
catalog:str | Undocumented |
Returns | |
Tuple[ | Undocumented |
Undocumented
Parameters | |
catalog:str | Undocumented |
namespace:str | Undocumented |
Returns | |
NullTranslations | Undocumented |
Undocumented
Parameters | |
catalog:str | Undocumented |
namespace:str | Undocumented |
Returns | |
bool | Undocumented |
Parameters | |
catalog:str | Undocumented |
namespace:str | Undocumented |
message:str | Undocumented |
Returns | |
str | 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.
Parameters | |
catalog:str | Undocumented |
namespace:str | Undocumented |
Returns | |
Callable | Undocumented |