<QtTranslation> Proxy Page

函数

QString qtTrId (const char * id , int n = -1)

QT_TRANSLATE_NOOP3 ( context , sourceText , disambiguation )
QT_TRANSLATE_NOOP ( context , sourceText )
QT_TRANSLATE_N_NOOP3 ( context , sourceText , comment )
QT_TRANSLATE_N_NOOP ( context , sourceText )
QT_TRID_NOOP ( id )
QT_TRID_N_NOOP ( id )
QT_TR_NOOP ( sourceText )
QT_TR_N_NOOP ( sourceText )

函数文档编制

QString qtTrId (const char * id , int n = -1)

The qtTrId function finds and returns a translated string.

Returns a translated string identified by id . If no matching string is found, the id itself is returned. This should not happen under normal conditions.

n >= 0, all occurrences of %n in the resulting string are replaced with a decimal representation of n . In addition, depending on n 's value, the translation text may vary.

Meta data and comments can be passed as documented for QObject::tr (). In addition, it is possible to supply a source string template like that:

//% <C string>

or

\begincomment% <C string> \endcomment

范例:

    //% "%n fooish bar(s) found.\n"
    //% "Do you want to continue?"
    QString text = qtTrId("qtn_foo_bar", n);
					

Creating QM files suitable for use with this function requires passing the -idbased 选项到 lrelease 工具。

警告: 此方法才可重入若有安装所有翻译器 before 调用此方法。不支持在履行翻译时,安装或移除翻译器。这样做可能会导致崩溃或其它不期望行为。

注意: 此函数是 可重入 .

另请参阅 QObject::tr (), QCoreApplication::translate (),和 Qt 国际化 .

宏文档编制

QT_TRANSLATE_NOOP3 ( context , sourceText , disambiguation )

Marks the UTF-8 encoded string literal sourceText for delayed translation in the given context 采用给定 disambiguation context is typically a class and also needs to be specified as a string literal. The string literal disambiguation should be a short semantic tag to tell apart otherwise identical strings.

The macro tells lupdate to collect the string, and expands to an anonymous struct of the two string literals passed as sourceText and disambiguation .

范例:

static { const char *source; const char *comment; } greeting_strings[] =
{
    QT_TRANSLATE_NOOP3("FriendlyConversation", "Hello",
                       "A really friendly hello"),
    QT_TRANSLATE_NOOP3("FriendlyConversation", "Goodbye",
                       "A really friendly goodbye")
};
QString FriendlyConversation::greeting(int type)
{
    return tr(greeting_strings[type].source,
              greeting_strings[type].comment);
}
QString global_greeting(int type)
{
    return qApp->translate("FriendlyConversation",
                           greeting_strings[type].source,
                           greeting_strings[type].comment);
}
					

另请参阅 QT_TR_NOOP (), QT_TRANSLATE_NOOP (),和 Qt 国际化 .

QT_TRANSLATE_NOOP ( context , sourceText )

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

范例:

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]);
}
					

另请参阅 QT_TR_NOOP (), QT_TRANSLATE_NOOP3 (),和 Qt 国际化 .

QT_TRANSLATE_N_NOOP3 ( context , sourceText , comment )

Marks the UTF-8 encoded string literal sourceText for numerator dependent delayed translation in the given context 采用给定 comment context is typically a class and also needs to be specified as a string literal. The string literal comment should be a short semantic tag to tell apart otherwise identical strings.

The macro tells lupdate to collect the string, and expands to an anonymous struct of the two string literals passed as sourceText and comment .

范例:

static { const char * const source; const char * const comment; } status_strings[] = {
    QT_TRANSLATE_N_NOOP3("Message Status", "Hello, you have %n message(s)",
                         "A login message status"),
    QT_TRANSLATE_N_NOOP3("Message status", "You have %n new message(s)",
                         "A new message query status")
};
QString FriendlyConversation::greeting(int type, int count)
{
    return tr(status_strings[type].source,
              status_strings[type].comment, count);
}
QString global_greeting(int type, int count)
{
    return qApp->translate("Message Status",
                           status_strings[type].source,
                           status_strings[type].comment,
                           count);
}
					

另请参阅 QT_TR_NOOP (), QT_TRANSLATE_NOOP (), QT_TRANSLATE_NOOP3 (),和 Qt 国际化 .

QT_TRANSLATE_N_NOOP ( context , sourceText )

Marks the UTF-8 encoded string literal sourceText for numerator dependent delayed translation in the given context 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 本身。

范例:

static const char * const greeting_strings[] = {
    QT_TRANSLATE_N_NOOP("Welcome Msg", "Hello, you have %n message(s)"),
    QT_TRANSLATE_N_NOOP("Welcome Msg", "Hi, you have %n message(s)")
};
QString global_greeting(int type, int msgcnt)
{
    return translate("Welcome Msg", greeting_strings[type], nullptr, msgcnt);
}
					

另请参阅 QT_TRANSLATE_NOOP (), QT_TRANSLATE_N_NOOP3 (),和 Qt 国际化 .

QT_TRID_NOOP ( id )

The QT_TRID_NOOP macro marks an id for dynamic translation.

The only purpose of this macro is to provide an anchor for attaching meta data like to qtTrId ().

The macro expands to id .

范例:

static const char * const ids[] = {
    //% "This is the first text."
    QT_TRID_NOOP("qtn_1st_text"),
    //% "This is the second text."
    QT_TRID_NOOP("qtn_2nd_text"),
    0
};
void TheClass::addLabels()
{
    for (int i = 0; ids[i]; ++i)
        new QLabel(qtTrId(ids[i]), this);
}
					

另请参阅 qtTrId () 和 Qt 国际化 .

[since 6.3] QT_TRID_N_NOOP ( id )

The QT_TRID_N_NOOP macro marks an id for numerator dependent dynamic translation.

The only purpose of this macro is to provide an anchor for attaching meta data like to qtTrId ().

The macro expands to id .

范例:

static const char * const ids[] = {
    //% "%n foo(s) found."
    QT_TRID_N_NOOP("qtn_foo"),
    //% "%n bar(s) found."
    QT_TRID_N_NOOP("qtn_bar"),
    0
};
QString result(int type, int n)
{
    return qtTrId(ids[type], n);
}
					

该宏在 Qt 6.3 引入。

另请参阅 qtTrId () 和 Qt 国际化 .

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 本身。

范例:

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

另请参阅 QT_TRANSLATE_NOOP () 和 Qt 国际化 .

QT_TR_N_NOOP ( sourceText )

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

The macro tells lupdate to collect the string, and expands to sourceText 本身。

The macro expands to sourceText .

范例:

static const char * const StatusClass::status_strings[] = {
    QT_TR_N_NOOP("There are %n new message(s)"),
    QT_TR_N_NOOP("There are %n total message(s)")
};
QString StatusClass::status(int type, int count)
{
    return tr(status_strings[type], nullptr, count);
}
					

另请参阅 QT_TR_NOOP and Qt 国际化 .