From c74bd2b9364ad2619eae5e72496b2ab7bb6041b8 Mon Sep 17 00:00:00 2001 From: Mateusz Starzycki Date: Tue, 28 Jun 2016 22:09:14 +0100 Subject: 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 Reviewed-by: Martin Smith --- .../snippets/code/src_corelib_global_qglobal.cpp | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp') diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp index 2d7b9a9ac8..9d029e5d4d 100644 --- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp @@ -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?" -- cgit v1.2.3