summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/src/snippets/code/src_corelib_kernel_qobject.cpp9
-rw-r--r--src/corelib/kernel/qobject.cpp28
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp19
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result21
-rw-r--r--tools/linguist/lupdate/cpp.cpp35
5 files changed, 107 insertions, 5 deletions
diff --git a/doc/src/snippets/code/src_corelib_kernel_qobject.cpp b/doc/src/snippets/code/src_corelib_kernel_qobject.cpp
index 5a7c5a7..5c0f80c 100644
--- a/doc/src/snippets/code/src_corelib_kernel_qobject.cpp
+++ b/doc/src/snippets/code/src_corelib_kernel_qobject.cpp
@@ -376,6 +376,15 @@ hostNameLabel->setText(tr("Name:"));
QString example = tr("Example");
//! [40]
+//! [meta data]
+//: This is a comment for the translator.
+//= qtn_foo_bar
+//~ loc-layout_id foo_dialog
+//~ loc-blank False
+//~ magic-stuff This might mean something magic.
+QString text = MyMagicClass::tr("Sim sala bim.");
+//! [meta data]
+
//! [explicit tr context]
QString text = QScrollBar::tr("Page up");
//! [explicit tr context]
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 9dc25c7..9e87b3b 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -2086,6 +2086,34 @@ void QObject::deleteLater()
\snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp 17
+ \section1 Meta Data
+
+ Additional data can be attached to each translatable message.
+ The syntax:
+
+ \tt{//= <id>}
+
+ can be used to give the message a unique identifier to support tools
+ which need it.
+ The syntax:
+
+ \tt{//~ <field name> <field contents>}
+
+ can be used to attach meta data to the message. The field name should consist
+ of a domain prefix (possibly the conventional file extension of the file format
+ the field is inspired by), a hyphen and the actual field name in
+ underscore-delimited notation. For storage in TS files, the field name together
+ with the prefix "extra-" will form an XML element name. The field contents will
+ be XML-escaped, but otherwise appear verbatim as the element's contents.
+ Any number of unique fields can be added to each message.
+
+ Example:
+
+ \snippet doc/src/snippets/code/src_corelib_kernel_qobject.cpp meta data
+
+ Meta data appearing right in front of a magic TRANSLATOR comment applies to the
+ whole TS file.
+
\section1 Character Encodings
You can set the encoding for \a sourceText by calling QTextCodec::setCodecForTr().
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
index df75baf..9fb43fe 100644
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
@@ -156,3 +156,22 @@ QT_TRANSLATE_NOOP3_UTF8("scope", "string", "comment") // 4.4 doesn't see this
QT_TRANSLATE_NOOP("scope", "string " // this is an interleaved comment
"continuation on next line")
+
+
+class TestingTake17 : QObject {
+ Q_OBJECT
+
+ int function(void)
+ {
+ //: random comment
+ //= this_is_an_id
+ //~ loc-layout_id fooish_bar
+ //~ po-ignore_me totally foo-barred nonsense
+ tr("something cool");
+
+ tr("less cool");
+
+ //= another_id
+ tr("even more cool");
+ }
+};
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
index 9386c19..5bd7525 100644
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
@@ -239,6 +239,27 @@
</message>
</context>
<context>
+ <name>TestingTake17</name>
+ <message id="this_is_an_id">
+ <location filename="main.cpp" line="170"/>
+ <source>something cool</source>
+ <extracomment>random comment</extracomment>
+ <translation type="unfinished"></translation>
+ <extra-po-ignore_me>totally foo-barred nonsense</extra-po-ignore_me>
+ <extra-loc-layout_id>fooish_bar</extra-loc-layout_id>
+ </message>
+ <message>
+ <location filename="main.cpp" line="172"/>
+ <source>less cool</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message id="another_id">
+ <location filename="main.cpp" line="175"/>
+ <source>even more cool</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
<name>scope</name>
<message numerus="yes">
<location filename="main.cpp" line="146"/>
diff --git a/tools/linguist/lupdate/cpp.cpp b/tools/linguist/lupdate/cpp.cpp
index 09148e7..b1d2d01 100644
--- a/tools/linguist/lupdate/cpp.cpp
+++ b/tools/linguist/lupdate/cpp.cpp
@@ -180,7 +180,8 @@ private:
QString transcode(const QString &str, bool utf8);
void recordMessage(
int line, const QString &context, const QString &text, const QString &comment,
- const QString &extracomment, bool utf8, bool plural);
+ const QString &extracomment, const QString &msgid, const TranslatorMessage::ExtraData &extra,
+ bool utf8, bool plural);
void processInclude(const QString &file, ConversionData &cd,
QSet<QString> &inclusions);
@@ -1299,13 +1300,16 @@ QString CppParser::transcode(const QString &str, bool utf8)
void CppParser::recordMessage(
int line, const QString &context, const QString &text, const QString &comment,
- const QString &extracomment, bool utf8, bool plural)
+ const QString &extracomment, const QString &msgid, const TranslatorMessage::ExtraData &extra,
+ bool utf8, bool plural)
{
TranslatorMessage msg(
transcode(context, utf8), transcode(text, utf8), transcode(comment, utf8), QString(),
yyFileName, line, QStringList(),
TranslatorMessage::Unfinished, plural);
msg.setExtraComment(transcode(extracomment.simplified(), utf8));
+ msg.setId(msgid);
+ msg.setExtras(extra);
if ((utf8 || yyForceUtf8) && !yyCodecIsUtf8 && msg.needs8Bit())
msg.setUtf8(true);
results->tor->append(msg);
@@ -1332,6 +1336,8 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
QString text;
QString comment;
QString extracomment;
+ QString msgid;
+ TranslatorMessage::ExtraData extra;
QString prefix;
#ifdef DIAGNOSE_RETRANSLATABILITY
QString functionName;
@@ -1604,9 +1610,11 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
prefix.clear();
}
- recordMessage(line, context, text, comment, extracomment, utf8, plural);
+ recordMessage(line, context, text, comment, extracomment, msgid, extra, utf8, plural);
}
extracomment.clear();
+ msgid.clear();
+ extra.clear();
break;
case Tok_translateUtf8:
case Tok_translate:
@@ -1655,9 +1663,11 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
break;
}
}
- recordMessage(line, context, text, comment, extracomment, utf8, plural);
+ recordMessage(line, context, text, comment, extracomment, msgid, extra, utf8, plural);
}
extracomment.clear();
+ msgid.clear();
+ extra.clear();
break;
case Tok_Q_DECLARE_TR_FUNCTIONS:
case Tok_Q_OBJECT:
@@ -1679,6 +1689,15 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
if (yyComment.startsWith(QLatin1Char(':'))) {
yyComment.remove(0, 1);
extracomment.append(yyComment);
+ } else if (yyComment.startsWith(QLatin1Char('='))) {
+ yyComment.remove(0, 1);
+ msgid = yyComment.simplified();
+ } else if (yyComment.startsWith(QLatin1Char('~'))) {
+ yyComment.remove(0, 1);
+ yyComment = yyComment.trimmed();
+ int k = yyComment.indexOf(QLatin1Char(' '));
+ if (k > -1)
+ extra.insert(yyComment.left(k), yyComment.mid(k + 1).trimmed());
} else {
comment = yyComment.simplified();
if (comment.startsWith(QLatin1String(MagicComment))) {
@@ -1689,7 +1708,11 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
} else {
context = comment.left(k);
comment.remove(0, k + 1);
- recordMessage(yyLineNo, context, QString(), comment, extracomment, false, false);
+ recordMessage(yyLineNo, context, QString(), comment, extracomment,
+ QString(), TranslatorMessage::ExtraData(), false, false);
+ extracomment.clear();
+ results->tor->setExtras(extra);
+ extra.clear();
}
}
}
@@ -1739,6 +1762,8 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
prospectiveContext.clear();
prefix.clear();
extracomment.clear();
+ msgid.clear();
+ extra.clear();
yyTokColonSeen = false;
yyTok = getToken();
break;