From 69d870a4863414be24ff6748f407559a7bb57f2f Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 14 Oct 2016 15:20:59 +0200 Subject: [PATCH] Preliminary work on translations support in dummypythonqt. --- src/modules/dummypythonqt/main.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/modules/dummypythonqt/main.py b/src/modules/dummypythonqt/main.py index 5b90235b7..714da6ad7 100644 --- a/src/modules/dummypythonqt/main.py +++ b/src/modules/dummypythonqt/main.py @@ -22,6 +22,21 @@ import platform from PythonQt.QtGui import * +# Set up translations. +# You may skip this if your Calamares module has no user visible strings. +# DO NOT install _ into the builtin namespace because each module loads +# its own catalog. +# DO use the gettext class-based API and manually alias _ as described in: +# https://docs.python.org/3.5/library/gettext.html#localizing-your-module +import gettext +import inspect +import os +filename = inspect.getframeinfo(inspect.currentframe()).filename +path = os.path.dirname(os.path.abspath(filename)) +t = gettext.translation('dummypythonqt', + os.path.join(path, 'lang')) +_ = t.lgettext + # Example Python ViewModule. # A Python ViewModule is a Python program which defines a ViewStep class. # This class must be marked with the @calamares_module decorator. A @@ -47,7 +62,7 @@ class DummyPythonQtViewStep(): label.text = accumulator btn = QPushButton() - btn.setText("Click me!") + btn.setText(_("Click me!")) self.main_widget.layout().addWidget(btn) btn.connect("clicked(bool)", self.on_btn_clicked)