简体   繁体   English

Qt 中的 QT_TRANSLATE_NOOP_UTF8 是什么?

[英]What is QT_TRANSLATE_NOOP_UTF8 for in Qt?

I cannot find any official documentation about QT_TRANSLATE_NOOP_UTF8 macro.我找不到任何关于 QT_TRANSLATE_NOOP_UTF8 宏的官方文档。 How does it works and what is "scope" argument?它是如何工作的,什么是“范围”参数? Is it namespace?是命名空间吗? And if it is, how to specify nested namespaces?如果是,如何指定嵌套的命名空间?

I've found documentation for it (it is hard to find but it is documented):我找到了它的文档(很难找到,但它已记录在案):

- Global Qt Declarations | - 全局 Qt 声明 | Qt Core 6.3.2 Qt 核心 6.3.2

QT_TR_NOOP( sourceText ) QT_TR_NOOP (源文本)

Marks the UTF-8 encoded string literal sourceText for delayed translation in the current context (class).将 UTF-8 编码的字符串文字sourceText标记为在当前上下文(类)中延迟翻译。

The macro tells lupdate to collect the string, and expands to sourceText itself.宏告诉 lupdate 收集字符串,并扩展到sourceText本身。

Example:例子:

 FriendlyConversation::greeting(int type) { static const char *greeting_strings[] = { QT_TR_NOOP("Hello"), QT_TR_NOOP("Goodbye") }; return tr(greeting_strings[type]); }

The macro QT_TR_NOOP_UTF8() is identical and obsolete;宏 QT_TR_NOOP_UTF8() 相同但已过时; this applies to all other _UTF8 macros as well .这也适用于所有其他 _UTF8 宏

See also QT_TRANSLATE_NOOP () and Internationalization with Qt .另请参阅QT_TRANSLATE_NOOP () 和Qt 国际化。

Note bold part.注意粗体部分。 So doesn't matter that this is for QT_TR_NOOP it applies also for:所以这对于QT_TR_NOOP并不重要,它也适用于:

- Global Qt Declarations | - 全局 Qt 声明 | Qt Core 6.3.2 Qt 核心 6.3.2

QT_TRANSLATE_NOOP( context , sourceText ) QT_TRANSLATE_NOOP上下文,源文本)

Marks the UTF-8 encoded string literal sourceText for delayed translation in the given context .将 UTF-8 编码的字符串文字sourceText标记为在给定上下文中延迟翻译。 The context is typically a class name and also needs to be specified as a string literal.上下文通常是类名,也需要指定为字符串文字。

The macro tells lupdate to collect the string, and expands to sourceText itself.宏告诉 lupdate 收集字符串,并扩展到sourceText本身。

Example:例子:

 static const char *greeting_strings[] = { QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"), QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye") }; QString FriendlyConversation::greeting(int type) { return tr(greeting_strings[type]); } QString global_greeting(int type) { return qApp->translate("FriendlyConversation", greeting_strings[type]); }

See also QT_TR_NOOP (), QT_TRANSLATE_NOOP3 (), and Internationalization with Qt .另请参阅QT_TR_NOOP ()、 QT_TRANSLATE_NOOP3 () 和Qt 国际化。

There is only a single mention of this macro in the qtbase repository:qtbase存储库中只提到了这个宏:

#define QT_TRANSLATE_NOOP_UTF8(scope, x) x

The macro has been there, almost unchanged and entirely undocumented, since at least 2011. It might be a backwards compatibility thing, but if so, it goes way back.至少自 2011 年以来,该宏就一直存在,几乎没有变化且完全没有文档记录。它可能是向后兼容的东西,但如果是这样,它可以追溯到很久以前。

From what I can tell , the translation tool Qt Linguist treats it in the same way as the more "official" QT_TRANSLATE_NOOP macro, which incidentally also accepts UTF-8 only.我所知,翻译工具 Qt Linguist 以与更“官方”的QT_TRANSLATE_NOOP宏相同的方式处理它,顺便说一下,它也只接受 UTF-8。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM