Translations using the m18n object

The moulinette provides a way to do translations and YunoHost uses it. This is done via the m18n object that you can import this way:

from moulinette import m18n

The m18n object comes with 2 method:

  • m18n.n to uses for translations within YunoHost
  • m18n.g to uses for translations within Moulinette itself

Their API is identical.

Here are example of uses:

m18n.n('some_translation_key')
m18n.g('some_translation_key')

m18n.n('some_translation_key', string_formating_argument_1=some_variable)
m18n.g('some_translation_key', string_formating_argument_1=some_variable)

The translation key must be present in locales/en.json of either YunoHost (for .n) or moulinette (for .g).

Docstring

As a reference, here are the docstrings of the m18n class:

class moulinette.core.Moulinette18n(default_locale='en')[source]

Internationalization service for the moulinette

Manage internationalization and access to the proper keys translation used in the moulinette and libraries.

Keyword arguments:
  • package – The current Package instance
  • default_locale – The default locale to use
Moulinette18n.n(key, *args, **kwargs)[source]

Retrieve proper translation for a moulinette key

Attempt to retrieve value for a key from current loaded namespace translations using the current locale or the default one if ‘key’ is not found.

Keyword arguments:
  • key – The key to translate
Moulinette18n.g(key, *args, **kwargs)[source]

Retrieve proper translation for a moulinette key

Attempt to retrieve value for a key from moulinette translations using the current locale or the default locale if ‘key’ is not found.

Keyword arguments:
  • key – The key to translate