I apologize for the silly question.
Let's assume we have an untranslated enigma2 plugin (e.g. MyPlugin), and we want to equip it with one or more translations.
Let's assume that the plugin syntax is correctly structured to make the strings we are interested in translatable.
Just as an example:
# plugin.py
def print_some_strings():
print(_("Hello world"))
print(_("This is a translatable string"))
if __name__=='__plugin__':
print_some_strings()
Let's assume that we have extracted all the translatable strings from the sources, created a .po file, translated the strings, and correctly compiled the .mo file that we are going to place in the right directory
...MyPlugin/locale/<language>/LC_MESSAGES/MyPlugin.mo
Using the file __init__.py we provide the information necessary to associate the path of the translations
Example:
# __init__.py
# -*- coding: utf-8 -*-
from Components.Language import language
from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_LANGUAGE
from os import environ as os_environ
import gettext
def localeInit():
lang = language.getLanguage()[:2] # getLanguage returns e.g. "fi_FI" for "language_country"
os_environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it!
gettext.bindtextdomain("MyPlugin", resolveFilename(SCOPE_PLUGINS, "Extensions/MyPlugin/locale"))
_ = lambda txt: gettext.dgettext("MyPlugin", txt)
localeInit()
language.addCallback(localeInit)
Alles anzeigen
What else needs to be done for the plugin code to use the translations dedicated to it?
Thanks in advance for the help