kepler.translation_util module¶
The module contains translation utility classes and functionality to manage translations per request. The translations are used by the document template system.
-
class
kepler.translation_util.Translations(locales, default_locale)¶ Bases:
objectSimple collection of translation strings for different locales.
A locale must be only the language part of the locale, e.g.
'en'and NOT'en_US'.Initializes the
Translationsobject.Parameters: - locales – Dictionary of translations for different locales.
- default_locale – Default locale name. Must correspond to one of the locales in the locales dictionary.
-
make_translator(request)¶ The method makes a new translator object from the request. The translator locale is determined by the
locale_namesession variable. If none is set, the locale name defaults toself.default_locale.Parameters: request – Pyramid request object. Returns: The translator for the current language determined using the request.
-
make_translator_from_locale(locale)¶ The method makes a new translator object from the given locale name.
Parameters: locale – The locale language part. Returns: The translator for the language specified by the locale.
-
class
kepler.translation_util.Translator(locale_name, strings)¶ Bases:
objectDefines a simple callable class for translator for localisation support.
A translator is responsible for translating to only one language. It returns the translation when an instance is called with translation id.
For example:
_ = Translator(translations) translated_text = _('my.translation.id') print(translated_text) # Prints e.g.: "My translation identifier"
The
Traslatorobject is constructed with a strings dictionary. The translation dictionary uses translation ID strings as the key to map them to the corresponding translation.Parameters: - locale_name – The locale name of the translator.
- strings – The translation string dictionary.
-
kepler.translation_util.setup_translations()¶ Setups the translations for use in document templates.
Returns: The Translationsobject containing all the translations in the system.