[PyQt] Translation troubles

Mikael Modin micke.modin at gmail.com
Mon Nov 8 21:27:39 GMT 2010


Hi,

I'm trying to translate a UI created using QDesigner, but I could
never get it working so I wrote a quick minimal non-working sample in
the hope that one of you could tell me what I'm doing wrong.

----------------------------  main.py
----------------------------------------------
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class Wnd(QDialog):
    def __init__(self):
        QDialog.__init__(self)
        self.setWindowTitle(self.tr("Title"))

def main():
    app = QApplication(sys.argv)
    translator = QTranslator()
    translator.load("main.ts")
    app.installTranslator(translator)
    wnd = Wnd()
    wnd.show()
    app.exec_()

if __name__ == '__main__':
    main()

------------------------------- main.ts
-------------------------------------------
The translation file I created using "pyuldate4 main.py -ts main.ts"
and then edited in QLinguist.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="sv_SE" sourcelanguage="en_GB">
<context>
    <name>Wnd</name>
    <message>
        <location filename="main.py" line="8"/>
        <source>Title</source>
        <translatorcomment>Blabla</translatorcomment>
        <translation>Muffins</translation>
    </message>
</context>
</TS>

Kind regards,
Mikael Modin


More information about the PyQt mailing list