Can I use tr(“”) and lupdate on *.xml files?

女生的网名这么多〃 提交于 2020-02-15 08:22:12

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/28166081/can-i-use-tr-and-lupdate-on-xml-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!