PDA

View Full Version : Qt Designer and id based translation



Gery
22nd January 2015, 06:51
Hi,
I use id based translation in my application. That means, that I use qtTrId() instead of tr() function. It works well, as I have most translatable strings in source code.
Problem is with forms generated by Qt Designer. Is it somehow possible to make lupdate generate contextless translates event for ui forms?

Thanks for help :)

anda_skoa
22nd January 2015, 09:13
It is possible to tell uic to use qtTrId as the translation function to which it then passes the text as the Id, but it seems to discard the comment (which in this case would be the source string) :(

Cheers,
_

Gery
22nd January 2015, 13:46
Thanks, I dont need source, so discarded comments are fine. Second thing is that lupdate still takes strings from ui file and not from generated header.

What I want to achieve is .ts file for all translatable strings like this:


<context>
<message id="tr_number__hint">
<source></source>
<translation type="unfinished"></translation>
</message>
<message id="tr_gsm__hint">
<source></source>
<translation>Translation</translation>
</message>
</context>

indtead of:


<context>
<name>core::InitialDialog</name>
<message>
<source>tr_number__hint</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>tr_gsm__hint</source>
<translation type="unfinished"></translation>
</message>
</context>

anda_skoa
22nd January 2015, 13:55
Hmm.

How about this:

- you move everything that you have in your .pro file other than FORMS to a .pri file
- you include that .pri file in your .pro
- you create a second .pro that includes the .pri and instead of FORMS adds the generated ui_*.h to SOURCES and uses that for lupdate's run

Cheers,
_

Gery
23rd January 2015, 11:49
Thank you, it works, but I still have a problem. When using uic with -tr qtTrid, it generates function like
qtTrId("tr_string", 0) That second parameter is wrong. I've solved that by downloading uic source and modifying it. Problem is, that I dont know how to make qmake use my uic.exe instead of the original one, which I dont want to replace. I've tried QMAKE_UIC but it does nothing.

anda_skoa
23rd January 2015, 14:12
Problem is, that I dont know how to make qmake use my uic.exe instead of the original one, which I dont want to replace. I've tried QMAKE_UIC but it does nothing.

Interesting, I would have also expected that QMAKE_UIC would be the means to that.

Maybe something like


load(uic)
uic.commands = .....


or creating a new uic command/target, like the new_moc example here http://qt-project.org/doc/qt-4.8/qmake-environment-reference.html#customizing

Cheers,
_