Install the following package
$ sudo apt-get install pyqt5-dev-tools
In my case it was also necessary to install this other package to use linguist
command
$ sudo apt-get install qt4-dev-tools
import os
omport sys
from PyQt5 import QtCore
from pyQt5.QtWidgets import QMainWindow, QApplication
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
# shortcut
self.translate = QtCore.QCoreApplication.translate
def my_method(self):
# translate(context, str)
mystring = self.translate('MainWindow', 'string to be translated')
-
create a file
app.pro
containing sources and destinations, i.e.:SOURCES += ../ottobackup.py SOURCES += ../dialog_settings.py SOURCES += ../dialog_info.py TRANSLATIONS += app_it.ts
-
generate the
ts
files:$ pylupdate5 app.pro
-
insert the translations:
$ linguist app_it.ts
-
compile the translation files:
$ lrelease app.pro
In the main part of the program
if __name__ == '__main__':
app = QApplication(sys.argv)
translator = QtCore.QTranslator(app)
lc_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'i18n',
'ottobackup_%s.qm' % QtCore.QLocale.system().name()[:2])
translator.load(lc_path)
app.installTranslator(translator)
main_window = MainWindow(application_data)
sys.exit(app.exec_())