Home > OS >  What is QT_TRANSLATE_NOOP_UTF8 for in Qt?
What is QT_TRANSLATE_NOOP_UTF8 for in Qt?

Time:07-20

I cannot find any official documentation about QT_TRANSLATE_NOOP_UTF8 macro. How does it works and what is "scope" argument? Is it namespace? And if it is, how to specify nested namespaces?

CodePudding user response:

I've found documentation for it (it is hard to find but it is documented):

- 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.

Note bold part. So doesn't matter that this is for QT_TR_NOOP it applies also for:

- 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.

CodePudding user response:

There is only a single mention of this macro in the qtbase repository:

#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.

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.

  •  Tags:  
  • c qt
  • Related