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

標記 UTF-8 編碼的字符串文字 sourceText for delayed translation in the given context 采用給定 disambiguationcontext 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 )

標記 UTF-8 編碼的字符串文字 sourceText for delayed translation in the given contextcontext 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 )

標記 UTF-8 編碼的字符串文字 sourceText for numerator dependent delayed translation in the given context 采用給定 commentcontext 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 )

標記 UTF-8 編碼的字符串文字 sourceText for numerator dependent delayed translation in the given contextcontext 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);
}
					

This macro was introduced in Qt 6.3.

另請參閱 qtTrId () 和 Qt 國際化 .

QT_TR_NOOP ( sourceText )

標記 UTF-8 編碼的字符串文字 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 )

標記 UTF-8 編碼的字符串文字 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 國際化 .