Commits

David Jean Louis committed 2d56f63

Fixed issue #8: POFile.merge error when an entry is obsolete in a .po, that this entry reappears in the .pot and that we merge the two.

  • Participants
  • Parent commits 230c1f0

Comments (0)

Files changed (4)

         fhandle.write(contents)
         fhandle.close()
 
-    def find(self, st, by='msgid'):
+    def find(self, st, by='msgid', include_obsolete_entries=False):
         """
         Find entry which msgid (or property identified by the *by*
         attribute) matches the string *st*.
         **Keyword arguments**:
           - *st*: string, the string to search for
           - *by*: string, the comparison attribute
+          - *include_obsolete_entries*: boolean, whether to also search in 
+            entries that are obsolete.
 
         **Examples**:
 
         for e in self:
             if getattr(e, by) == st:
                 return e
+        if include_obsolete_entries:
+            for e in self.obsolete_entries():
+                if getattr(e, by) == st:
+                    return e
         return None
 
     def ordered_metadata(self):
         True
         """
         for entry in refpot:
-            e = self.find(entry.msgid)
+            e = self.find(entry.msgid, include_obsolete_entries=True)
             if e is None:
                 e = POEntry()
                 self.append(e)
         """
         Merge the current entry with the given pot entry.
         """
-        self.msgid        = other.msgid
-        self.occurrences  = other.occurrences
-        self.comment      = other.comment
-        self.flags        = other.flags
+        self.msgid = other.msgid
+        self.msgctxt = other.msgctxt
+        self.occurrences = other.occurrences
+        self.comment = other.comment
+        self.flags = other.flags
         self.msgid_plural = other.msgid_plural
+        self.obsolete = other.obsolete
+        self.previous_msgctxt = other.previous_msgctxt
+        self.previous_msgid = other.previous_msgid
+        self.previous_msgid_plural = other.previous_msgid_plural
         if other.msgstr_plural:
             for pos in other.msgstr_plural:
                 try:

File tests/test_merge.pot

 msgid_plural "monthes"
 msgstr[0] ""
 msgstr[1] ""
+
+#: foo/bar.py:30
+msgid ""
+"This entry should be removed after the merge and added again as non "
+"obsolete entry"
+msgstr "Some translation"

File tests/test_merge_after.po

 msgstr[0] "année"
 msgstr[1] "années"
 
+#: foo/bar.py:30
+msgid ""
+"This entry should be removed after the merge and added again as non "
+"obsolete entry"
+msgstr "Some translation"
+
 #: some/file.py:3 some/file2.py:4
 msgid "This entry is not present in pofile and will be appended"
 msgstr ""

File tests/test_merge_before.po

 msgid_plural "years"
 msgstr[0] "année"
 msgstr[1] "années"
+
+#~ msgid ""
+#~ "This entry should be removed after the merge and added again as non "
+#~ "obsolete entry"
+#~ msgstr "Some translation"