Hello,
it seems that whether the translation works depends on the context where
QApplication.installTranslator is called.
The following code works as it should:
from PyQt4 import QtCore, QtGui
app = QtGui.QApplication([])
translator = QtCore.QTranslator()
translator.load("hello_de")
app.installTranslator(translator)
hello = QtGui.QPushButton(QtGui.QApplication.translate("Test","Hello
World!"))
hello.resize(100, 30)
hello.show()
app.exec_()
In contrast, the next application does not display the translated text,
although I simply moved the initialization into a function:
from PyQt4 import QtCore, QtGui
def init():
app = QtGui.QApplication([])
translator = QtCore.QTranslator()
translator.load("hello_de")
app.installTranslator(translator)
return app
app = init()
hello = QtGui.QPushButton(QtGui.QApplication.translate("Test","Hello
World!"))
hello.resize(100, 30)
hello.show()
app.exec_()
Did I make a mistake or is this a difference between PyQt and Qt? As far as
I understand, this is not covered by "Differences Between PyQt and Qt" (
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/i18n.html) and
seems not to be documented elsewhere.
The appendix contains the ts-file that I used.
Thanks,
Martin Altmayer
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="de">
<context>
<name>Test</name>
<message>
<location filename="hello.py" line="11"/>
<source>Hello World!</source>
<translation>Hallo Welt!</translation>
</message>
</context>
</TS>
_______________________________________________
PyQt mailing list [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt