improve documentation, mostly of the QT_TR*_NOOP macros

Change-Id: I65ccddec84a01945a6aee2a859d4f92ea830785b
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
Reviewed-by: Mateusz Starzycki <mstarzycki@gmail.com>
Reviewed-by: Martin Smith <martin.smith@qt.io>
This commit is contained in:
Oswald Buddenhagen 2018-04-12 21:10:59 +02:00
parent b55176df08
commit 395a19f032
3 changed files with 38 additions and 38 deletions

View File

@ -387,11 +387,11 @@ CONFIG += no_keywords
//! [34] //! [34]
QString FriendlyConversation::greeting(int type) QString FriendlyConversation::greeting(int type)
{ {
static const char *greeting_strings[] = { static const char *greeting_strings[] = {
QT_TR_NOOP("Hello"), QT_TR_NOOP("Hello"),
QT_TR_NOOP("Goodbye") QT_TR_NOOP("Goodbye")
}; };
return tr(greeting_strings[type]); return tr(greeting_strings[type]);
} }
//! [34] //! [34]
@ -410,7 +410,7 @@ QString FriendlyConversation::greeting(int type)
QString global_greeting(int type) QString global_greeting(int type)
{ {
return qApp->translate("FriendlyConversation", return qApp->translate("FriendlyConversation",
greeting_strings[type]); greeting_strings[type]);
} }
//! [35] //! [35]
@ -434,8 +434,8 @@ QString FriendlyConversation::greeting(int type)
QString global_greeting(int type) QString global_greeting(int type)
{ {
return qApp->translate("FriendlyConversation", return qApp->translate("FriendlyConversation",
greeting_strings[type].source, greeting_strings[type].source,
greeting_strings[type].comment); greeting_strings[type].comment);
} }
//! [36] //! [36]

View File

@ -648,10 +648,10 @@ Q_STATIC_ASSERT((std::is_same<qsizetype, qptrdiff>::value));
compiler or platform specific code to their application. compiler or platform specific code to their application.
The remaining macros are convenience macros for larger operations: The remaining macros are convenience macros for larger operations:
The QT_TRANSLATE_NOOP() and QT_TR_NOOP() macros provide the The QT_TR_NOOP(), QT_TRANSLATE_NOOP(), and QT_TRANSLATE_NOOP3()
possibility of marking text for dynamic translation, macros provide the possibility of marking strings for delayed
i.e. translation without changing the stored source text. The translation.
Q_ASSERT() and Q_ASSERT_X() enables warning messages of various The Q_ASSERT() and Q_ASSERT_X() enables warning messages of various
level of refinement. The Q_FOREACH() and foreach() macros level of refinement. The Q_FOREACH() and foreach() macros
implement Qt's foreach loop. implement Qt's foreach loop.
@ -662,11 +662,11 @@ Q_STATIC_ASSERT((std::is_same<qsizetype, qptrdiff>::value));
memory, if the pointer is 0. The qPrintable() and qUtf8Printable() memory, if the pointer is 0. The qPrintable() and qUtf8Printable()
macros represent an easy way of printing text. macros represent an easy way of printing text.
Finally, the QT_POINTER_SIZE macro expands to the size of a The QT_POINTER_SIZE macro expands to the size of a pointer in bytes.
pointer in bytes, and the QT_VERSION and QT_VERSION_STR macros
expand to a numeric value or a string, respectively, specifying The macros QT_VERSION and QT_VERSION_STR expand to a numeric value
Qt's version number, i.e the version the application is compiled or a string, respectively, that specifies the version of Qt that the
against. application is compiled against.
\sa <QtAlgorithms>, QSysInfo \sa <QtAlgorithms>, QSysInfo
*/ */
@ -3676,19 +3676,18 @@ bool qunsetenv(const char *varName)
\macro QT_TR_NOOP(sourceText) \macro QT_TR_NOOP(sourceText)
\relates <QtGlobal> \relates <QtGlobal>
Marks the string literal \a sourceText for dynamic translation in Marks the UTF-8 encoded string literal \a sourceText for delayed
the current context (class), i.e the stored \a sourceText will not translation in the current context (class).
be altered.
The macro expands to \a sourceText. The macro tells lupdate to collect the string, and expands to
\a sourceText itself.
Example: Example:
\snippet code/src_corelib_global_qglobal.cpp 34 \snippet code/src_corelib_global_qglobal.cpp 34
The macro QT_TR_NOOP_UTF8() is identical except that it tells lupdate The macro QT_TR_NOOP_UTF8() is identical and obsolete; this applies
that the source string is encoded in UTF-8. Corresponding variants to all other _UTF8 macros as well.
exist in the QT_TRANSLATE_NOOP() family of macros, too.
\sa QT_TRANSLATE_NOOP(), {Internationalization with Qt} \sa QT_TRANSLATE_NOOP(), {Internationalization with Qt}
*/ */
@ -3697,12 +3696,12 @@ bool qunsetenv(const char *varName)
\macro QT_TRANSLATE_NOOP(context, sourceText) \macro QT_TRANSLATE_NOOP(context, sourceText)
\relates <QtGlobal> \relates <QtGlobal>
Marks the string literal \a sourceText for dynamic translation in Marks the UTF-8 encoded string literal \a sourceText for delayed
the given \a context; i.e, the stored \a sourceText will not be translation in the given \a context. The \a context is typically
altered. The \a context is typically a class and also needs to a class name and also needs to be specified as a string literal.
be specified as string literal.
The macro expands to \a sourceText. The macro tells lupdate to collect the string, and expands to
\a sourceText itself.
Example: Example:
@ -3712,18 +3711,19 @@ bool qunsetenv(const char *varName)
*/ */
/*! /*!
\macro QT_TRANSLATE_NOOP3(context, sourceText, comment) \macro QT_TRANSLATE_NOOP3(context, sourceText, disambiguation)
\relates <QtGlobal> \relates <QtGlobal>
\since 4.4 \since 4.4
Marks the string literal \a sourceText for dynamic translation in the Marks the UTF-8 encoded string literal \a sourceText for delayed
given \a context and with \a comment, i.e the stored \a sourceText will translation in the given \a context with the given \a disambiguation.
not be altered. The \a context is typically a class and also needs to The \a context is typically a class and also needs to be specified
be specified as string literal. The string literal \a comment as a string literal. The string literal \a disambiguation should be
will be available for translators using e.g. Qt Linguist. a short semantic tag to tell apart otherwise identical strings.
The macro expands to anonymous struct of the two string The macro tells lupdate to collect the string, and expands to an
literals passed as \a sourceText and \a comment. anonymous struct of the two string literals passed as \a sourceText
and \a disambiguation.
Example: Example:

View File

@ -1062,7 +1062,7 @@ template <typename Wrapper> static inline typename Wrapper::pointer qGetPtrHelpe
#define QT_TRANSLATE_NOOP3(scope, x, comment) {x, comment} #define QT_TRANSLATE_NOOP3(scope, x, comment) {x, comment}
#define QT_TRANSLATE_NOOP3_UTF8(scope, x, comment) {x, comment} #define QT_TRANSLATE_NOOP3_UTF8(scope, x, comment) {x, comment}
#ifndef QT_NO_TRANSLATION // ### This should enclose the NOOPs above #ifndef QT_NO_TRANSLATION // ### Qt6: This should enclose the NOOPs above
// Defined in qcoreapplication.cpp // Defined in qcoreapplication.cpp
// The better name qTrId() is reserved for an upcoming function which would // The better name qTrId() is reserved for an upcoming function which would