QT_TR_NOOP:生成了翻译文件,但从未使用过翻译后的字符串,为什么?
在应用程序中,我有很多显然不是 QObject 后代的类,并且这些对象显然会引发异常,并且这些异常显然需要进行转换。因此,我将抛出异常的每个字符串都包含在 QT_TR_NOOP 宏中。这使我能够生成翻译文件。但是当我运行我的程序时,字符串仍然没有被翻译。如果我尝试通过 QApplication::translate ("MyClassName", "Text in english") 获取它们,我可以很好地获取字符串,但 QT_TR_NOOP ("Text in english") 仅返回英文文本。我需要采取任何额外的步骤才能使其正常工作吗?
另外,还有一个小问题:如果我在不属于任何类的函数中使用 QT_TR_NOOP,会发生什么? Qt会默默地忽略这种情况吗?
In an application I have a lot of classes that are apparently not descendants of QObject, and these objects apparently throw exceptions, and those exceptions apparently need to be translated. So, I enclosed every string thrown in exception in QT_TR_NOOP macro. That allowed me to generate translation files. But when I run my program, strings are still not translated. If I try to get them via QApplication::translate ("MyClassName", "Text in english"), I can get strings fine, but QT_TR_NOOP ("Text in english") returns just text in english. Are there any extra steps I should take to make it work right?
Also, a little side question: if I'm using QT_TR_NOOP in a function that is not a member of any class, what will happen? Does Qt just silently ignore this situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来我把整个事情搞错了:(
QT_TR_NOOP 用于标记函数外部翻译的字符串;它应该返回原始文本。我需要的是将翻译应用于非 qt 类,这在此处详细描述:
Qt 国际化:翻译非 Qt课程
抱歉打扰了。
It seems that I got the whole thing wrong :(
QT_TR_NOOP is for marking strings for translation outside functions; it is supposed to return original text. What I needed was to apply translations to the non-qt classes, which is described in detail here:
Internationalization with Qt: Translating Non-Qt Classes
Sorry for bothering.
QT_TR_NOOP 仅将文本标记为可能需要翻译的内容(以便它显示在 Qt Linguist 中),但它不执行任何翻译。为此,您需要使用 tr()。
QT_TR_NOOP only marks the text as something that may need translation (so that it shows up in Qt Linguist) but it doesn't do any translating. For that you need to use tr().