Can I use tr ("") and lupdate in * .xml files?

This is a shot in the dark, but is there any way to use qt ("") in an XML file somehow? To generate .ts files as follows:

lupdate myXML.xml -ts myML.ts 

I tried this command but it does not work. This does not give me an error, it just says that 0 (zero) literals were found. I mean, the documentation says something like this:

lupdate is a tool that scans the source files for tr () and places the lines in an .ts XML file. At this point, the .ts file contains only lines intended for translation.

It talks about the source file and does not specify which file is supported, so I think it should support different types of files; but how to do that?

+3
xml qt internationalization
source share
1 answer

So, I found a solution using QT_TRANSLATE_NOOP :

In the following XML, I am doing something like this:

 <root> <tag>QT_TRANSLATE_NOOP("context","value")</tag> </root> 

And when I want to get the value, I do something like this in cpp:

  Q_INVOKABLE QString getTranslation(QString value){ return QApplication::translate("context", value); } 

So, to summarize in a few words. I put the QT_TRANSLATE_NOOP macro in my XML file containing the context string (you can select whatever you want) and the value I want it to be translated. Therefore, when I do lupdate myxml.xml -ts myTs.ts, it generates a ts file that has value as the source text in the context specified in the macro. After that, in cpp, I have to create a function that dynamically transfers the translation from the context.

+1
source share

All Articles