API Documentation¶
The Translation Manager Module (hoshi.i18n
)¶
This module provides the main interfaces to hoshi
.
- class hoshi.i18n.TranslationManager(supported_languages, catalog_dirs)[source]¶
Bases:
object
The TranslationManager object is the primary interface of the library to application code. Most applications using hoshi will instantiate this class exactly once and hold the instance in a globally accessible namespace, such as the application or config object.
This class manages the translation contexts, locales, and external translators.
- Parameters
supported_languages – A list of languages / locales the application intends to support
catalog_dirs – A list of directories which hold the translation templates and catalogs
- property catalog_dirs¶
- property log¶
- property primary_language¶
- install_language(language)[source]¶
Install a single language to the application’s locale set. This function uses babel to install the appropriate locale, which can later be used to render things like dates, numbers, and currencies.
Locales should not be used directly, and instead should be used using the translator.
It is currently not intended for languages to be installed on the fly. Do this before creating any contexts or attempting any translations.
- Parameters
language – locale code in the form ‘en_US’
- install_context(context_name, language, catalog_dir=None, metadata=None)[source]¶
Install an i18n context. Language would be a locale code of the form “en_US”. While not mandated, context name would typically be of the form “<module>”.
i18n Contexts are objects which can manage specific i18n strategies and contain and apply special helper functions for translating a string.
- _i18n_msg(context, message)[source]¶
Translate an atomic string message using the provided context. Conversion by this function applies a standard gettext / po mechanism. If the string is not included in the i18n catalogs, it will be added for later manual translation. Note that the po files will be updated only on the next application run.
- _translate(context, obj, *args, **kwargs)[source]¶
Translate a translatable object using the provided context. This function should dispatch to specific functions depending on the type of the object. If the context has special helper / preprocessing functions installed, they are applied here. - Numbers, dates, times, currencies : Locale - Strings : _i18n