lib.translation

This library implements the translation support for the core and the plugins.

Bemerkung

Translations for the Administration Interface (Javascript) are not done through this API!

The translations for the webinterfaces are handled by this library, because the translations are done in Python and not on the html/Javascript side of the code.

The API is implemented through the following library:

This library implements the multi language support of SmartHomeNG.

It is used in
  • lib.module

  • lib.shtime

  • lib.model.module

  • lib.model.smartplugin

The shortcut _(…) for translate(…) is defined in class SmartPluginWebIf() SmartPluginWebIf() which is defined in lib.model.smartplugin.py

If is a replacement when rendering templates using Jinja2:

tplenv.globals[‚_‘] = self.translate

lib.translation.initialize_translations(base_dir, default_language, fallback_language_order)[Quellcode]

Initialize the multi-language support

Parameter:
  • base_dir – Base directory of SmartHomeNG

  • default_language – language to be used for translations: ‚de‘, ‚en‘, ‚fr‘, …

  • fallback_language_order – string with the fallback langauges (komma seperated)

lib.translation.set_default_language(language)[Quellcode]

Set language to be used for translations

Parameter:

language – language to be used for translations: ‚de‘, ‚en‘, ‚fr‘, …

lib.translation.set_fallback_language_order(language_order)[Quellcode]

Set fallback languages and their order

Fallback languages are used, if a translation for the selected default_language is not available

Parameter:

language_order – string with the fallback langauges (komma seperated)

lib.translation.load_translations(translation_type='global', from_dir='bin', translation_id='global')[Quellcode]

Load global or plugin-specific translations from a locale.yaml file

Parameter:
  • translation_type – ‚global‘ or ‚plugin‘

  • from_dir – ‚bin‘ (for global) or ‚plugins/<plugin name>‘

Rückgabe:

loaded translations as s dict

lib.translation.reload_translations()[Quellcode]

Reload translations for existing translation_ids - to test new translations without having to restart SmartHomeNG

lib.translation.translate(txt, vars=None, plugin_translations=None, module_translations=None, additional_translations=None)[Quellcode]

Returns translated text

Parameter:
  • txt – TEXT TO TRANSLATE

  • vars – dict with variables to replace in the translated text

  • plugin_translations – ID for additional translations (if None, only global translations are used)

  • module_translations – ID for additional translations (if None, only global and plugin translations are used)

Rückgabe:

Translated text