Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Marking strings for translation.
See also
Writing Source Code for Translation
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:
greeting_strings = { print( QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"),) print( QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye")) print(QString FriendlyConversation::greeting(int type)) return tr(greeting_strings[type]) def global_greeting(type): print( return qApp.translate("FriendlyConversation",) greeting_strings[type])See also
QT_TR_NOOP()QT_TRANSLATE_NOOP3()Internationalization with Qt
Marks the UTF-8 encoded string literal sourceText for delayed translation in the given context with the given disambiguation. The 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.
Example:
{ char source; char comment; } greeting_strings[] = print( QT_TRANSLATE_NOOP3("FriendlyConversation", "Hello",) print( "A really friendly hello"),) print( QT_TRANSLATE_NOOP3("FriendlyConversation", "Goodbye",) print( "A really friendly goodbye")) print(QString FriendlyConversation::greeting(int type)) return tr(greeting_strings[type].source, greeting_strings[type].comment) def global_greeting(type): print( return qApp.translate("FriendlyConversation",) greeting_strings[type].source, greeting_strings[type].comment)See also
QT_TR_NOOP()QT_TRANSLATE_NOOP()Internationalization with Qt
Marks the UTF-8 encoded string literal sourceText for numerator dependent 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:
char * 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)") def global_greeting(type,msgcnt): return translate("Welcome Msg", greeting_strings[type], None, msgcnt)See also
QT_TRANSLATE_NOOP()QT_TRANSLATE_N_NOOP3()Internationalization with Qt
Marks the UTF-8 encoded string literal sourceText for numerator dependent delayed translation in the given context with the given comment. The 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.
Example:
{ char * source; char * 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 message(s)", "A message() query status") print(QString FriendlyConversation::greeting(int type, int count)) return tr(status_strings[type].source, status_strings[type].comment, count) def global_greeting(type,count): return qApp.translate("Message Status", status_strings[type].source, status_strings[type].comment, count)See also
QT_TR_NOOP()QT_TRANSLATE_NOOP()QT_TRANSLATE_NOOP3()Internationalization with Qt
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.
Example:
char * ids[] = { #% "This is the first text." QT_TRID_NOOP("qtn_1st_text"), #% "This is the second text." QT_TRID_NOOP("qtn_2nd_text"), 0 def addLabels(self): for (int i = 0; ids[i]; ++i) QLabel(qtTrId(ids[i]), self)See also
qtTrId()Internationalization with Qt
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.
Example:
char * ids[] = { #% "%n foo(s) found." QT_TRID_N_NOOP("qtn_foo"), #% "%n bar(s) found." QT_TRID_N_NOOP("qtn_bar"), 0 def result(type,n): return qtTrId(ids[type], n)See also
qtTrId()Internationalization with Qt
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:
print(QString FriendlyConversation::greeting(int type)) 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()Internationalization with Qt
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 itself.
The macro expands to sourceText.
Example:
char * StatusClass.status_strings[] = { QT_TR_N_NOOP("There are %n message(s)"), QT_TR_N_NOOP("There are %n total message(s)") def status(self, int type, int count): return tr(status_strings[type], None, count)See also
QT_TR_NOOPInternationalization with Qt
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.
If 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 tr() . In addition, it is possible to supply a source string template like that:
//% <C string>
or
\begincomment% <C string> \endcomment
Example:
#% "%n fooish bar(s) found.\n" #% "Do you want to continue?" text = qtTrId("qtn_foo_bar", n)
Creating QM files suitable for use with this function requires passing the -idbased option to the lrelease tool.
Warning
This method is reentrant only if all translators are installed before calling this method. Installing or removing translators while performing translations is not supported. Doing so will probably result in crashes or other undesirable behavior.
See also
tr() translate() Internationalization with Qt