Add QT_TR*_N_NOOP() macros
[ChangeLog][QtCore][Global] Added the QT_TR_N_NOOP(), QT_TRANSLATE_N_NOOP(), and QT_TRANSLATE_N_NOOP3() macros for numeral dependent delayed translation. Change-Id: I57c5b1ad4006267f49a57b0cbc40216b8e0399ff Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Martin Smith <martin.smith@qt.io>
This commit is contained in:
parent
878a82f188
commit
c74bd2b936
@ -440,6 +440,54 @@ QString global_greeting(int type)
|
||||
//! [36]
|
||||
|
||||
|
||||
//! [qttrnnoop]
|
||||
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);
|
||||
}
|
||||
//! [qttrnnoop]
|
||||
|
||||
//! [qttranslatennoop]
|
||||
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);
|
||||
}
|
||||
//! [qttranslatennoop]
|
||||
|
||||
//! [qttranslatennoop3]
|
||||
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);
|
||||
}
|
||||
//! [qttranslatennoop3]
|
||||
|
||||
|
||||
//! [qttrid]
|
||||
//% "%n fooish bar(s) found.\n"
|
||||
//% "Do you want to continue?"
|
||||
|
@ -650,7 +650,8 @@ Q_STATIC_ASSERT((std::is_same<qsizetype, qptrdiff>::value));
|
||||
The remaining macros are convenience macros for larger operations:
|
||||
The QT_TR_NOOP(), QT_TRANSLATE_NOOP(), and QT_TRANSLATE_NOOP3()
|
||||
macros provide the possibility of marking strings for delayed
|
||||
translation.
|
||||
translation. QT_TR_N_NOOP(), QT_TRANSLATE_N_NOOP(), and
|
||||
QT_TRANSLATE_N_NOOP3() are numerator dependent variants of these.
|
||||
The Q_ASSERT() and Q_ASSERT_X() enables warning messages of various
|
||||
level of refinement. The Q_FOREACH() and foreach() macros
|
||||
implement Qt's foreach loop.
|
||||
@ -3732,6 +3733,71 @@ bool qunsetenv(const char *varName)
|
||||
\sa QT_TR_NOOP(), QT_TRANSLATE_NOOP(), {Internationalization with Qt}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\macro QT_TR_N_NOOP(sourceText)
|
||||
\relates <QtGlobal>
|
||||
\since 5.12
|
||||
|
||||
Marks the UTF-8 encoded string literal \a sourceText for numerator
|
||||
dependent delayed translation in the current context (class).
|
||||
|
||||
The macro tells lupdate to collect the string, and expands to
|
||||
\a sourceText itself.
|
||||
|
||||
The macro expands to \a sourceText.
|
||||
|
||||
Example:
|
||||
|
||||
\snippet code/src_corelib_global_qglobal.cpp qttrnnoop
|
||||
|
||||
\sa QT_TR_NOOP, {Internationalization with Qt}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\macro QT_TRANSLATE_N_NOOP(context, sourceText)
|
||||
\relates <QtGlobal>
|
||||
\since 5.12
|
||||
|
||||
Marks the UTF-8 encoded string literal \a sourceText for numerator
|
||||
dependent delayed translation in the given \a context.
|
||||
The \a 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
|
||||
\a sourceText itself.
|
||||
|
||||
Example:
|
||||
|
||||
\snippet code/src_corelib_global_qglobal.cpp qttranslatennoop
|
||||
|
||||
\sa QT_TRANSLATE_NOOP(), QT_TRANSLATE_N_NOOP3(),
|
||||
{Internationalization with Qt}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\macro QT_TRANSLATE_N_NOOP3(context, sourceText, comment)
|
||||
\relates <QtGlobal>
|
||||
\since 5.12
|
||||
|
||||
Marks the UTF-8 encoded string literal \a sourceText for numerator
|
||||
dependent delayed translation in the given \a context with the given
|
||||
\a disambiguation.
|
||||
The \a context is typically a class and also needs to be specified
|
||||
as a string literal. The string literal \a 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 \a sourceText
|
||||
and \a disambiguation.
|
||||
|
||||
Example:
|
||||
|
||||
\snippet code/src_corelib_global_qglobal.cpp qttranslatennoop3
|
||||
|
||||
\sa QT_TR_NOOP(), QT_TRANSLATE_NOOP(), QT_TRANSLATE_NOOP3(),
|
||||
{Internationalization with Qt}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QString qtTrId(const char *id, int n = -1)
|
||||
\relates <QtGlobal>
|
||||
|
@ -1064,6 +1064,10 @@ template <typename Ptr> inline auto qGetPtrHelper(const Ptr &ptr) -> decltype(pt
|
||||
|
||||
#ifndef QT_NO_TRANSLATION // ### Qt6: This should enclose the NOOPs above
|
||||
|
||||
#define QT_TR_N_NOOP(x) x
|
||||
#define QT_TRANSLATE_N_NOOP(scope, x) x
|
||||
#define QT_TRANSLATE_N_NOOP3(scope, x, comment) {x, comment}
|
||||
|
||||
// Defined in qcoreapplication.cpp
|
||||
// The better name qTrId() is reserved for an upcoming function which would
|
||||
// return a much more powerful QStringFormatter instead of a QString.
|
||||
|
Loading…
Reference in New Issue
Block a user