Anonymous avatar Anonymous committed ac2fa20

fixed issue 12: improved merge() method

Comments (0)

Files changed (4)

         for entry in refpot:
             e = self.find(entry.msgid)
             if e is None:
-                # entry is not in the po file, we must add it
-                # entry is created with msgid, occurrences and comment
-                self.append(POEntry(
-                    msgid=entry.msgid,
-                    occurrences=entry.occurrences,
-                    comment=entry.comment
-                ))
-            else:
-                # entry found, we update it...
-                e.occurrences = entry.occurrences
-                e.comment = entry.comment
+                e = POEntry()
+                self.append(e)
+            e.merge(entry)
         # ok, now we must "obsolete" entries that are not in the refpot
         # anymore
         for entry in self:
         else: return -1
 
     def translated(self):
-        """Return True if the entry has been translated or False"""
+        """
+        Return True if the entry has been translated or False.
+        """
         if self.obsolete or 'fuzzy' in self.flags:
             return False
         if self.msgstr != '':
             return True
         return False
 
+    def merge(self, other):
+        """
+        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_plural = other.msgid_plural
+        if other.msgstr_plural:
+            for pos in other.msgstr_plural:
+                try:
+                    # keep existing translation at pos if any
+                    self.msgstr_plural[pos]
+                except KeyError:
+                    self.msgstr_plural[pos] = ''
+
 # }}}
 # class MOEntry {{{
 

tests/test_merge.pot

 #: some/file.py:3 some/file2.py:4
 msgid "This entry is not present in pofile and will be appended"
 msgstr ""
+
+#: utils/timesince.py:12
+msgid "year"
+msgid_plural "years"
+msgstr[0] ""
+msgstr[1] ""
+
+#: utils/timesince.py:40
+msgid "month"
+msgid_plural "monthes"
+msgstr[0] ""
+msgstr[1] ""

tests/test_merge_after.po

 msgstr ""
 "Project-Id-Version: django\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2007-08-17 15:35-0400\n"
+"POT-Creation-Date: 2007-12-13 10:00+0100\n"
 "PO-Revision-Date: 2007-07-14 13:00-0500\n"
 "Last-Translator: Mario Gonzalez <gonzalemario @t gmail.com>\n"
 "Language-Team: Castellano <Django-I18N@googlegroups.com>\n"
 msgid "This entry is already present in pofile, but with different occurrences"
 msgstr "Some translation ..."
 
+#: utils/timesince.py:12
+msgid "year"
+msgid_plural "years"
+msgstr[0] "année"
+msgstr[1] "années"
+
 #: some/file.py:3 some/file2.py:4
 msgid "This entry is not present in pofile and will be appended"
 msgstr ""
 
+#: utils/timesince.py:40
+msgid "month"
+msgid_plural "monthes"
+msgstr[0] ""
+msgstr[1] ""
+
 #~ msgid "This entry is not present in potfile and will be obsoleted"
 #~ msgstr "Some translation"

tests/test_merge_before.po

 msgstr ""
 "Project-Id-Version: django\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2007-08-17 15:35-0400\n"
+"POT-Creation-Date: 2007-12-13 10:00+0100\n"
 "PO-Revision-Date: 2007-07-14 13:00-0500\n"
 "Last-Translator: Mario Gonzalez <gonzalemario @t gmail.com>\n"
 "Language-Team: Castellano <Django-I18N@googlegroups.com>\n"
 #: some/file.py:3 some/file2.py:4
 msgid "This entry is not present in potfile and will be obsoleted"
 msgstr "Some translation"
+
+#: utils/timesince.py:12
+msgid "year"
+msgid_plural "years"
+msgstr[0] "année"
+msgstr[1] "années"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.