PDA

View Full Version : PyQt and i18n, only "half of it" is translated



NebuK
15th January 2008, 11:47
Hi,

i wrote a project in pyqt and wanted to let it do i18n now. so i wrapped all my texts in self.tr() and wrote a .pro file like this:

SOURCES = main.py models.py
FORMS = ui/beans.ui ui/blends.ui ui/edit.ui ui/mainWindow.ui ui/profile.ui ui/roast.ui ui/select.ui ui/settings.ui ui/temptime.ui
TRANSLATIONS = roasterbase_de.ts


then i did a pylupdate4 on that pro-file and translated everything in linguist. ran lrelease on the pro file and it says that ~140 finished entries are there. now i installed a translator onto my QApplication:

app = QtGui.QApplication(sys.argv)

translator = QTranslator()
print translator.load("roasterbase_de.qm", ".")

app.installTranslator(translator)

load() returns true. Thing is, only half of the stuff is translated, only a few dialogs but not all and some table headings - but again not all...

where could i start looking for the error?

Thanks in advance
- Dario

PS: the project is available on svn://ghostdub.de/roasterbase

jacek
15th January 2008, 21:57
Do these untranslated strings come from your code or are part of Qt?

NebuK
16th January 2008, 08:52
Partially from my code an partially from the pyuic4 converted qt-designer files...

jacek
16th January 2008, 16:00
Check if you don't have more than one roasterbase_de.qm file, delete all of them and run lrelease once more.

Could post the location in your code where such untranslated string appears?

NebuK
17th January 2008, 07:31
Example would be all strings from beans.py (created from ui/beans.ui).

Just deleted the .qm and retranslated everything, still the same :/.

thanks for the help so far!
- Dario

wysota
17th January 2008, 10:14
Please post the example code, not the repository address.

NebuK
17th January 2008, 10:23
Hi,

i somehow resisted to post two such long files ... also the BBS didnt allow me to post them, so i nopasted them. How i install the QTranslator is in my first post. Here the files, ui and pyuic4 generated:
http://rafb.net/p/HfZ0sF93.html
http://rafb.net/p/9fI0ir88.html

wysota
17th January 2008, 10:53
Couldn't you have just pasted the parts of the files that are relevant to the problem?

BTW. I don't think that ui files or autogenerated files will get us anywhere... We can assume they are ok.

NebuK
17th January 2008, 12:01
Well, what code should i post then? Its mainly the Strings from the pyuic generated files.

Another example would be main.py 365,


self.fcMarker1 = Qwt.QwtPlotMarker()
[...]
label = self.fcMarker1.label()
label.setText(self.tr('first Crack'))


where the last line is 365. 'first Crack' is transted to "Erstes Knacken" in linguist, howver "first Crack" still shows up. On the other hand all headers in models.py are translated:

def headerData(self, section, orientation, role):
if role==0 and orientation==1:
if section==0:
return QtCore.QVariant(self.tr("Name"))
elif section==1:
return QtCore.QVariant(self.tr("Country"))
elif section==2:
return QtCore.QVariant(self.tr("Stock"))
return QtCore.QVariant()

ALL strings from uic-generated files aren't translated except temptime.[py,ui] - if i only knew whats different with this one...

thanks again so far :P
- Dario

wysota
17th January 2008, 12:07
Check if the .ts files contain correct translations and if the strings are marked as translated.

NebuK
17th January 2008, 12:36
Everything alright on that side - or at least it looks to me like it is. I nopasted the .ts file, so maybe someone could doublecheck: http://rafb.net/p/wHxClu46.txt

Thanks once again :P
- Dario

jacek
17th January 2008, 14:00
What happens if you change one of the working translations and regenerate the .qm file? Can you see the change in your application?

wysota
17th January 2008, 14:05
I nopasted the .ts file, so maybe someone could doublecheck

And why not use the attachment feature from this forum?

NebuK
17th January 2008, 14:06
Heho,

just tried, changes are visible...

jacek
17th January 2008, 20:00
What happens if you change labels for downButton and upButton in beans.ui to "down" and "up" (or similar)?

NebuK
21st January 2008, 10:02
Hi,

also no luck with that, those unicode-chars dont seem to do any harm.

greeting
- dario

wysota
21st January 2008, 11:53
Try deleting all intermediate files (.pyc included) and rebuild the project.

NebuK
22nd January 2008, 10:24
i do that everytime i try ...

i also tried again with using both, the uic generated files in SOURCES= and the .ui files in FORMS=. Another thing i tried is letting the classes generated by pyuic4 be inherited from QObject and using self.tr instead of the QtGui.QApplication.translate provided by pyuic ... doesnt work too :/.

wysota
22nd January 2008, 13:03
Could you see if the problem is persistent across applications? I mean if the same happens for a clean simple and small application written from scratch.

NebuK
24th January 2008, 13:47
Just created a mainwindow with only 2 labels, one set from the source, and one set from the ui file. i then again tried both, including the .ui or the uic4-generated .py in the .pro and translating. Didnt work - only the label i set from source worked, ui didnt.

wysota
24th January 2008, 14:25
Did you call retranslateUi() or a PyQt equivalent?

NebuK
25th January 2008, 10:37
As far as i can see retranslateui is beeing called at the end of setupui ... it shouldnt be nessecarry to call it manually again. however i just tried, didnt work :/