Question

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...

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top