c++ - Qt 中的 QT_TRANSLATE_NOOP_UTF8 是什么?

标签 c++ qt

我找不到任何有关 QT_TRANSLATE_NOOP_UTF8 宏的官方文档。 它是如何工作的以及什么是“范围”论证?是命名空间吗?如果是,如何指定嵌套命名空间?

最佳答案

我找到了它的文档(很难找到,但有文档记录):

- Global Qt Declarations | Qt Core 6.3.2

QT_TR_NOOP(sourceText)

Marks the UTF-8 encoded string literal sourceText for delayed translation in the current context (class).

The macro tells lupdate to collect the string, and expands to sourceText itself.

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; this applies to all other _UTF8 macros as well.

See also QT_TRANSLATE_NOOP() and Internationalization with Qt.

注意粗体部分。因此,这适用于 QT_TR_NOOP 并不重要,它也适用于:

- Global Qt Declarations | Qt Core 6.3.2

QT_TRANSLATE_NOOP(context, sourceText)

Marks the UTF-8 encoded string literal sourceText for delayed translation in the given context. 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.

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.

关于c++ - Qt 中的 QT_TRANSLATE_NOOP_UTF8 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73048664/

相关文章:

c++ - 从带有 opengl 代码的 C++ 转换为带有 GUI 的 QT 应用程序?

c++ - QGraphicsObject(0) 而不是指针中的 NULL

c++ - 最烦解析更烦

c++ - 对类构造函数的 undefined reference

c++ - 使用最新的 C++ 以类型安全的方式从枚举中随机选择一个元素

c++ - 如何从 json 文件读取值数组到 C++ 数组

c++ - 位字段的 offsetof 和 sizeof 类似功能

c++ - 成员初始化列表错误中的模板基构造函数调用

Qt 使用 QueuedConnection 将两个信号连接在一起

c++ - 将一个 header 包含到我的 MVS 项目时出错