Reputation: 1998
This is a shot in the dark but is there a way to use somehow qt("") in an xml file? To generate the .ts files like this?:
lupdate myXML.xml -ts myML.ts
I tried this command but it doesn't work. It doesn't give me an error, it simply says that 0(zero) literals found. I mean the documentation says something like this:
lupdate – A tool that scans the source files for tr() and places the strings in a .ts xml file. At this point the .ts file contains only strings that are meant to be translated.
It says about a source file and doesn't stipulates what kind of file is supported, so I think it should support various types of files; but how to do it?
Upvotes: 4
Views: 1177
Reputation: 1998
Ok so I found the solution using QT_TRANSLATE_NOOP:
In the following xml text i do something like this:
<root>
<tag>QT_TRANSLATE_NOOP("context","value")</tag>
</root>
And when I want to fetch the value I do something like this in cpp:
Q_INVOKABLE QString getTranslation(QString value){
return QApplication::translate("context", value);
}
So to sum up in a few words. I put the macro QT_TRANSLATE_NOOP in my xml file containing a context string(you can choose whatever you want) and the value that I want it to be translated. So when I do lupdate myxml.xml -ts myTs.ts it generates a ts file having the value as the source text within the context specified in the macro. After that in cpp I must create a function that dynamically takes the translation from the context.
Upvotes: 1