PDA

View Full Version : How to populate text entries to ts file from some other FIles (Localization)



vaibhav
20th April 2011, 10:48
Hi,
I have an application which reads some file which has information about the widgets like below.

Pushbutton
tooltips :"THIS IS TO CREATE THE NAME"
texts :"NAME"
width:100
height:200

This at run time creates the QPUSHBUTTON with text as NAME and tooltip as "THIS IS TO CREATE THE NAME".

Now I want to provide the localization for these texts and tooltips which are not written in .cpp or .h files.
So running lupdate directly on .pro file wont work.
So guys do you have any approch of populating all texts from such file's to .ts ? .

Thanks....

stampede
20th April 2011, 12:54
You can use QT_TRANSLATE_NOOP macro:


Pushbutton
tooltips :QT_TRANSLATE_NOOP("ButtonTooltips","THIS IS TO CREATE THE NAME")
texts :QT_TRANSLATE_NOOP("ButtonNames","NAME")
width:100
height:200

Then add this script to list of headers in .pro file, it will be parsed when you call lupdate <project file>.
You can alter your parser to extract the tooltip text and button name from this script as well as translation context, and then translate the string, for example, like this (context and text are strings extracted from QT_TRANSLATE_NOOP macro from script):

qApp->translate(context.toAscii().constData(),text.toAsc ii().constData());
It will work, I've done something like this some time ago.
If you have better solution, I'll be happy to know it.

vaibhav
23rd May 2011, 10:21
I wrote a script which extract all the tootip and text from my file and i wrote all those text in new file (say tr_translate.h ) under QT_TR_NLOOP() and then i run lupdate on tr_translate.h file .
This way i don need to manually add

#tooltips :QT_TRANSLATE_NOOP("ButtonTooltips","THIS IS TO CREATE THE NAME")
#texts :QT_TRANSLATE_NOOP("ButtonNames","NAME")

in every file of mine .