Localization for dynamically generated text.
Hi,
I have a XML file which has the text for all the Widgets that i am using in my application.
I read this XML file at runtime and set the text for my widgets.
Now i want to create localization for these texts which are in that XML files.
lupdate doesn't recognize the texts used to create ts files for this case.
Literals String works fine like pushbutton->setText(tr("Hi"));
But something like pushbutton->setText(strText);
where strText is QString which contains the text from that XML file .
lupdate doesn't recognize for latter text to create ts file .
Any help would be appreciated.
Thanks .
Re: Localization for dynamically generated text.
You need to wrap all the possible literal strings into QT_TR_NOOP calls apart from using tr for the translation:
Code:
QString FriendlyConversation
::greeting(int type
) { static const char *greeting_strings[] = {
QT_TR_NOOP("Hello"),
QT_TR_NOOP("Goodbye")
};
return tr(greeting_strings[type]);
}
Other than that I would suggest to apply an xsl transformation on your original xml file to make it conformant with Qt's .ts files. Then you just don't need lupdate.
Re: Localization for dynamically generated text.
Thanks .
Could you elaborate more on second point about XSL.
Re: Localization for dynamically generated text.
Re: Localization for dynamically generated text.
How do you imagine to have localized text from custom data? If text from file is none deterministic then it is impossible (extremely hard) to provide proper translations! For example see google translate.
If you have well defined texts then IMHO you trying to do something strange what should be handled fully by Qt localization engine.
Write what you are trying to do not how you try to achieve this.
Re: Localization for dynamically generated text.
I have some 50 files from which i read these texts.These are not the .cpp or .h files but the files which stores the text for some widgets.
The way QT lupdate reads all the literals withen the file(.cpp or .h) wraped under tr() and creates .ts for it.
In similar way i want some approch by which my texts from those 50 file be the part of ts file so that i can provide the translation for the same.
Re: Localization for dynamically generated text.
So use XSLT or store your texts in a format compliant with .ts file structure.
Re: Localization for dynamically generated text.
Sorry But thses are not the XML files but some format read by my application.It not only stores the text but the other widget information like height with color etc.
I cant change these files either.
Re: Localization for dynamically generated text.
So convert them. How many times do I have to repeat myself? Or build a custom backend for QTranslator around your files.
Re: Localization for dynamically generated text.
I may sound little foolish but how to build a custom backend for QTranslator around my files.
Re: Localization for dynamically generated text.