trac.util.translation
¶
Utilities for text translation with gettext.
Functions¶
-
trac.util.translation.
deactivate
()¶ Deactivate translations. :return: the current Translations, if any
-
trac.util.translation.
reactivate
(t)¶ Reactivate previously deactivated translations. :param t: the Translations, as returned by
deactivate
-
trac.util.translation.
make_activable
(get_locale, env_path=None)¶ Defer activation of translations. :param get_locale: a callable returning a Babel Locale object :param env_path: the environment to use for looking up catalogs
-
trac.util.translation.
get_available_locales
()¶ Return a list of locale identifiers of the locales for which translations are available.
-
trac.util.translation.
domain_functions
(domain, *symbols)¶ Prepare partial instantiations of domain translation functions.
Parameters: - domain – domain used for partial instantiation
- symbols – remaining parameters are the name of commonly used translation function which will be bound to the domain
Note: the symbols can also be given as an iterable in the 2nd argument.
-
trac.util.translation.
s_dgettext
(domain, msgid, **kwargs)¶ Retrieves translations for “squeezed” messages, in a domain.
See
s_gettext
for additional details.
-
trac.util.translation.
s_gettext
(msgid, **kwargs)¶ Retrieves translations for “squeezed” messages (in default domain).
Squeezed messages are text blocks in which white-space has been simplified during extraction (see
trac.dist.extract_html
). The catalog contain msgid with minimal whitespace. As a consequence, the msgid have to be normalized as well at retrieval time (i.e. here).This typically happens for trans blocks and gettext functions in Jinja2 templates, as well as all the text extracted from legacy Genshi templates.
Internals¶
-
class
trac.util.translation.
NullTranslationsBabel
(fp=None)¶ Bases:
gettext.NullTranslations
NullTranslations doesn’t have the domain related methods.
-
class
trac.util.translation.
TranslationsProxy
¶ Bases:
object
Delegate Translations calls to the currently active Translations.
If there’s none, wrap those calls in LazyProxy objects.
Activation is controlled by
activate
anddeactivate
methods. However, if retrieving the locale information is costly, it’s also possible to enable activation on demand only, by providing a callable tomake_activable
.