tools/linguist/lupdate/merge.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/tools/linguist/lupdate/merge.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/tools/linguist/lupdate/merge.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -247,10 +247,8 @@
         t = translated.find(zeroKey((*u).sourceText()));
         if (t != translated.end() && !t.key().isEmpty()
             && t->sourceText() != u->sourceText()) {
-            TranslatorMessage m = *u;
-            m.setTranslation(translationAttempt(t->translation(), t->sourceText(),
-                                                u->sourceText()));
-            tor.replace(m);
+            u->setTranslation(translationAttempt(t->translation(), t->sourceText(),
+                                                 u->sourceText()));
             inserted++;
         }
     }
@@ -305,9 +303,7 @@
         QString key = u->sourceText();
         t = translated.find(key);
         if (t != translated.end()) {
-            TranslatorMessage m = *u;
-            m.setTranslations(t->translations());
-            tor.replace(m);
+            u->setTranslations(t->translations());
             ++inserted;
         }
     }
@@ -345,15 +341,17 @@
     foreach (TranslatorMessage m, tor.messages()) {
         TranslatorMessage::Type newType = TranslatorMessage::Finished;
 
-        if (m.sourceText().isEmpty()) {
+        if (m.sourceText().isEmpty() && m.id().isEmpty()) {
             // context/file comment
             TranslatorMessage mv = virginTor.find(m.context());
             if (!mv.isNull())
                 m.setComment(mv.comment());
         } else {
-            TranslatorMessage mv = virginTor.find(m.context(), m.sourceText(), m.comment());
-            if (mv.isNull()) {
+            TranslatorMessage mv;
+            int mvi = virginTor.find(m);
+            if (mvi < 0) {
                 if (!(options & HeuristicSimilarText)) {
+                  makeObsolete:
                     newType = TranslatorMessage::Obsolete;
                     if (m.type() != TranslatorMessage::Obsolete)
                         obsoleted++;
@@ -362,10 +360,7 @@
                     mv = virginTor.find(m.context(), m.comment(), m.allReferences());
                     if (mv.isNull()) {
                         // did not find it in the virgin, mark it as obsolete
-                        newType = TranslatorMessage::Obsolete;
-                        if (m.type() != TranslatorMessage::Obsolete)
-                            obsoleted++;
-                        m.clearReferences();
+                        goto makeObsolete;
                     } else {
                         // Do not just accept it if its on the same line number,
                         // but different source text.
@@ -380,6 +375,7 @@
                             ++similarTextHeuristicCount;
                             neww++;
 
+                          outdateSource:
                             m.setOldSourceText(m.sourceText());
                             m.setSourceText(mv.sourceText());
                             const QString &oldpluralsource = m.extra(QLatin1String("po-msgid_plural"));
@@ -387,38 +383,45 @@
                                 m.setExtra(QLatin1String("po-old_msgid_plural"), oldpluralsource);
                                 m.unsetExtra(QLatin1String("po-msgid_plural"));
                             }
-                            m.setReferences(mv.allReferences()); // Update secondary references
-                            m.setPlural(mv.isPlural());
-                            m.setUtf8(mv.isUtf8());
-                            m.setExtraComment(mv.extraComment());
+                            goto copyAttribs; // Update secondary references
                         } else {
                             // The virgin and vernacular sourceTexts are so
                             // different that we could not find it.
-                            newType = TranslatorMessage::Obsolete;
-                            if (m.type() != TranslatorMessage::Obsolete)
-                                obsoleted++;
-                            m.clearReferences();
+                            goto makeObsolete;
                         }
                     }
                 }
             } else {
-                switch (m.type()) {
-                case TranslatorMessage::Finished:
-                default:
-                    if (m.isPlural() == mv.isPlural()) {
-                        newType = TranslatorMessage::Finished;
-                    } else {
-                        newType = TranslatorMessage::Unfinished;
-                    }
+                mv = virginTor.message(mvi);
+                if (!mv.id().isEmpty()
+                    && (mv.context() != m.context()
+                        || mv.sourceText() != m.sourceText()
+                        || mv.comment() != m.comment())) {
                     known++;
-                    break;
-                case TranslatorMessage::Unfinished:
                     newType = TranslatorMessage::Unfinished;
-                    known++;
-                    break;
-                case TranslatorMessage::Obsolete:
-                    newType = TranslatorMessage::Unfinished;
-                    neww++;
+                    m.setContext(mv.context());
+                    m.setComment(mv.comment());
+                    if (mv.sourceText() != m.sourceText())
+                        goto outdateSource;
+                } else {
+                    switch (m.type()) {
+                    case TranslatorMessage::Finished:
+                    default:
+                        if (m.isPlural() == mv.isPlural()) {
+                            newType = TranslatorMessage::Finished;
+                        } else {
+                            newType = TranslatorMessage::Unfinished;
+                        }
+                        known++;
+                        break;
+                    case TranslatorMessage::Unfinished:
+                        newType = TranslatorMessage::Unfinished;
+                        known++;
+                        break;
+                    case TranslatorMessage::Obsolete:
+                        newType = TranslatorMessage::Unfinished;
+                        neww++;
+                    }
                 }
 
                 // Always get the filename and linenumber info from the
@@ -426,10 +429,12 @@
                 // This should also enable us to read a file that does not
                 // have the <location> element.
                 // why not use operator=()? Because it overwrites e.g. userData.
+              copyAttribs:
                 m.setReferences(mv.allReferences());
                 m.setPlural(mv.isPlural());
                 m.setUtf8(mv.isUtf8());
                 m.setExtraComment(mv.extraComment());
+                m.setId(mv.id());
             }
         }
 
@@ -442,11 +447,11 @@
       vernacular translator.
     */
     foreach (const TranslatorMessage &mv, virginTor.messages()) {
-        if (mv.sourceText().isEmpty()) {
+        if (mv.sourceText().isEmpty() && mv.id().isEmpty()) {
             if (tor.contains(mv.context()))
                 continue;
         } else {
-            if (tor.contains(mv.context(), mv.sourceText(), mv.comment()))
+            if (tor.find(mv) >= 0)
                 continue;
             if (options & HeuristicSimilarText) {
                 TranslatorMessage m = tor.find(mv.context(), mv.comment(), mv.allReferences());
@@ -460,7 +465,7 @@
             outTor.append(mv);
         else
             outTor.appendSorted(mv);
-        if (!mv.sourceText().isEmpty())
+        if (!mv.sourceText().isEmpty() || !mv.id().isEmpty())
             ++neww;
     }