update message index when message gains source text
authorOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Mon, 27 Apr 2015 18:36:32 +0000 (20:36 +0200)
committerOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Thu, 30 Apr 2015 09:22:40 +0000 (09:22 +0000)
when a message which is first seen with only an id later gains a source
text, this text would not have been indexed. so a subsequent new message
with the same source, but without an id this time around, would not be
seen as a dupe of the first message.

Change-Id: Ib35f820e2b02311ea9c9996383a2789095098d6f
Reviewed-by: hjk <hjk@theqtcompany.com>
src/linguist/shared/translator.cpp
tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result

index 94d3bc3..f976596 100644 (file)
@@ -151,7 +151,9 @@ void Translator::extend(const TranslatorMessage &msg, ConversionData &cd)
     } else {
         TranslatorMessage &emsg = m_messages[index];
         if (emsg.sourceText().isEmpty()) {
+            delIndex(index);
             emsg.setSourceText(msg.sourceText());
+            addIndex(index, msg);
         } else if (!msg.sourceText().isEmpty() && emsg.sourceText() != msg.sourceText()) {
             cd.appendError(QString::fromLatin1("Contradicting source strings for message with id '%1'.")
                            .arg(emsg.id()));
index 074ed66..4fdd489 100644 (file)
@@ -394,3 +394,19 @@ Class42::hello(int something /*= 17 */, QString str = Class42::tr("eyo"))
 
 // test TR_EXCLUDE
 #include "notincluded.cpp"
+
+
+
+// failure to update index on insertion messes up subsequent de-duplication
+int dupeFail()
+{
+    // First just the Id.
+    qtTrId("dupe_id");
+
+    // Then with source
+    //% "This is the source"
+    qtTrId("dupe_id");
+
+    // Finally, same source, but without ID.
+    QCoreApplication::translate("", "This is the source");
+}
index c0a4a83..0c0c1b5 100644 (file)
@@ -24,6 +24,13 @@ backslashed \ stuff.</source>
         <extracomment>This is a message without a source string</extracomment>
         <translation type="unfinished"></translation>
     </message>
+    <message id="dupe_id">
+        <location filename="main.cpp" line="404"/>
+        <location filename="main.cpp" line="408"/>
+        <location filename="main.cpp" line="411"/>
+        <source>This is the source</source>
+        <translation type="unfinished"></translation>
+    </message>
 </context>
 <context>
     <name>Bogus</name>