<QtTranslation>
Contrassegnare le stringhe da tradurre. Altro...
| Header: | #include <QtTranslation> |
Funzioni
| QString | qtTrId(const char *id, int n = -1) |
Macro
| 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) | |
(since 6.3) | QT_TRID_N_NOOP(id) |
| QT_TR_NOOP(sourceText) | |
| QT_TR_N_NOOP(sourceText) |
Vedi anche Scrittura del codice sorgente per la traduzione.
Documentazione sulle funzioni
QString qtTrId(const char *id, int n = -1)
La funzione qtTrId individua e restituisce una stringa tradotta.
Restituisce una stringa tradotta identificata dall'id. Se non viene trovata alcuna stringa corrispondente, viene restituito l'id stesso. Ciò non dovrebbe verificarsi in condizioni normali.
Se n >= 0, tutte le occorrenze di %n nella stringa risultante vengono sostituite con una rappresentazione decimale di n. Inoltre, a seconda del valore di n, il testo della traduzione può variare.
I metadati e i commenti possono essere passati come documentato per QObject::tr(). Inoltre, è possibile fornire un modello di stringa sorgente come questo:
//% <C string>
oppure
\begincomment% <C string> \endcomment
Esempio:
//% "%n fooish bar(s) found.\n"
//% "Do you want to continue?"
QString text = qtTrId("qtn_foo_bar", n);Per creare file QM adatti all’uso con questa funzione è necessario passare l’opzione -idbased allo strumento lrelease.
Avviso: questo metodo è rientrante solo se tutti i traduttori sono installati prima di chiamare questo metodo. L'installazione o la rimozione di traduttori durante l'esecuzione delle traduzioni non è supportata. Ciò comporterà probabilmente arresti anomali o altri comportamenti indesiderati.
Nota: questa funzione è rientrante.
Vedi anche QObject::tr(), QCoreApplication::translate() e Internazionalizzazione con Qt.
Documentazione sulle macro
QT_TRANSLATE_NOOP3(context, sourceText, disambiguation)
Contrassegna il letterale stringa codificato in UTF-8 sourceText per la traduzione differita nel context specificato con l'disambiguation specificato. L'context è in genere una classe e deve essere specificato anch'esso come letterale stringa. Il letterale stringa disambiguation dovrebbe essere un breve tag semantico per distinguere stringhe altrimenti identiche.
La macro indica a lupdate di raccogliere la stringa e si espande in una struttura anonima composta dai due letterali stringa passati come sourceText e disambiguation.
Esempio:
static struct { 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);
}Vedi anche QT_TR_NOOP(), QT_TRANSLATE_NOOP() e Internazionalizzazione con Qt.
QT_TRANSLATE_NOOP(context, sourceText)
Contrassegna la stringa letterale codificata in UTF-8 sourceText per la traduzione differita nel context specificato. Il context è in genere un nome di classe e deve essere specificato anch’esso come stringa letterale.
La macro indica a lupdate di raccogliere la stringa e si espande in sourceText stesso.
Esempio:
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]);
}Vedi anche QT_TR_NOOP(), QT_TRANSLATE_NOOP3() e Internazionalizzazione con Qt.
QT_TRANSLATE_N_NOOP3(context, sourceText, comment)
Contrassegna il letterale stringa codificato in UTF-8 sourceText per la traduzione ritardata dipendente dal numeratore nell'context specificato con l'comment specificato. L'context è in genere una classe e deve essere specificato anch'esso come letterale stringa. Il letterale stringa comment dovrebbe essere un breve tag semantico per distinguere stringhe altrimenti identiche.
La macro indica a lupdate di raccogliere la stringa e si espande in una struttura anonima composta dai due letterali stringa passati come sourceText e comment.
Esempio:
static struct { 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);
}Vedi anche QT_TR_NOOP(), QT_TRANSLATE_NOOP(), QT_TRANSLATE_NOOP3() e Internazionalizzazione con Qt.
QT_TRANSLATE_N_NOOP(context, sourceText)
Contrassegna il letterale stringa codificato in UTF-8 sourceText per la traduzione ritardata dipendente dal numeratore nel context specificato. Il context è in genere un nome di classe e deve essere specificato anch’esso come letterale stringa.
La macro indica a lupdate di raccogliere la stringa e si espande in sourceText stesso.
Esempio:
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);
}Vedi anche QT_TRANSLATE_NOOP(), QT_TRANSLATE_N_NOOP3() e Internazionalizzazione con Qt.
QT_TRID_NOOP(id)
La macro QT_TRID_NOOP contrassegna un ID per la traduzione dinamica.
L'unico scopo di questa macro è fornire un punto di riferimento per associare metadati come qtTrId().
La macro si espande in ` id`.
Esempio:
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);
}Vedi anche ` qtTrId()` e Internazionalizzazione con Qt.
[since 6.3] QT_TRID_N_NOOP(id)
La macro QT_TRID_N_NOOP contrassegna un ID per la traduzione dinamica dipendente dal numeratore.
L'unico scopo di questa macro è fornire un punto di riferimento per associare metadati come qtTrId().
La macro si espande in ` id`.
Esempio:
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);
}Questa macro è stata introdotta in Qt 6.3.
Vedi anche ` qtTrId()` e Internazionalizzazione con Qt.
QT_TR_NOOP(sourceText)
Contrassegna la stringa letterale codificata in UTF-8 sourceText per la traduzione differita nel contesto corrente (classe).
La macro indica a lupdate di raccogliere la stringa e si espande in sourceText.
Esempio:
QString FriendlyConversation::greeting(int type)
{
static const char *greeting_strings[] = {
QT_TR_NOOP("Hello"),
QT_TR_NOOP("Goodbye")
};
return tr(greeting_strings[type]);
}La macro QT_TR_NOOP_UTF8() è identica ed è obsoleta; ciò vale anche per tutte le altre macro _UTF8.
Vedi anche QT_TRANSLATE_NOOP() e Internazionalizzazione con Qt.
QT_TR_N_NOOP(sourceText)
Contrassegna la stringa letterale codificata in UTF-8 sourceText per la traduzione ritardata dipendente dal numeratore nel contesto corrente (classe).
La macro indica a lupdate di raccogliere la stringa e si espande in sourceText.
La macro si espande in sourceText.
Esempio:
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);
}Vedi anche QT_TR_NOOP e Internazionalizzazione con Qt.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.