我可以在* .xml文件中使用tr(“")和lupdate吗? [英] Can I use tr("") and lupdate on *.xml files?

查看:154
本文介绍了我可以在* .xml文件中使用tr(“")和lupdate吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在黑暗中拍摄的照片,但是有没有办法在XML文件中以某种方式使用qt(")?要生成这样的.ts文件?:

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

我尝试了此命令,但是它不起作用.它没有给我一个错误,它只是说找到了0(零)个文字. 我的意思是文档中说的是这样的:

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 –一种工具,用于扫描源文件中的tr()并将字符串放在.ts xml文件中.此时,.ts文件仅包含要翻译的字符串.

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?

推荐答案

好,所以我使用 QT_TRANSLATE_NOOP 找到了解决方案:

Ok so I found the solution using QT_TRANSLATE_NOOP:

在以下xml文本中,我这样做:

In the following xml text i do something like this:

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

当我想获取值时,我会在cpp中执行以下操作:

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);
    }

因此,用几句话总结一下.我将宏QT_TRANSLATE_NOOP放在我的xml文件中,该文件包含上下文字符串(您可以选择所需的任何内容)和要翻译的值.因此,当我执行lupdate myxml.xml -ts myTs.ts时,它会生成一个ts文件,该文件的值作为宏中指定的上下文中的源文本.之后,在cpp中,我必须创建一个函数,该函数可以动态地从上下文中获取翻译.

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.

这篇关于我可以在* .xml文件中使用tr(“")和lupdate吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆