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

查看:34
本文介绍了我可以在 *.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天全站免登陆