Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add multi language support to a python QT program

How would I go about adding multi language support to a program, that is written in python, with a QT frontend?

For instance when you ran it and your environments language was set to english it would open a window saying hello, but if your environment was set to spanish it would say hola.

I'm not really sure where to start, so if someone could point me in the right direction to some tutorials, or some documentation on how to do it, I would greatly appreciate it.

EDIT: I should add, I'm using pyqt4

Edit: Ok, I have generated all the translation .qm files, but how do I go about adding the python code to use them? There is even less information about this it looks like...

like image 506
Joshua Strot Avatar asked Oct 21 '25 09:10

Joshua Strot


1 Answers

The answer I eventually came up with was using the code below.

from PyQt4 import QtCore, QtGui
from locale import getdefaultlocale

app = QtGui.QApplication(sys.argv)

locale = getdefaultlocale()

translator = QtCore.QTranslator(app)
translator.load('/usr/share/my_app/tr/qt_%s.qm' % locale[0])
app.installTranslator(translator)
like image 69
Joshua Strot Avatar answered Oct 24 '25 05:10

Joshua Strot