Index: translate/storage/base.py =================================================================== --- translate/storage/base.py (revision 8018) +++ translate/storage/base.py (working copy) @@ -301,8 +301,8 @@ """Build a native unit from a foreign unit, preserving as much information as possible.""" - if type(unit) == cls and hasattr(unit, "copy") and callable(unit.copy): - return unit.copy() + #if type(unit) == cls and hasattr(unit, "copy") and callable(unit.copy): + # return unit.copy() newunit = cls(unit.source) newunit.target = unit.target newunit.markfuzzy(unit.isfuzzy()) @@ -374,7 +374,7 @@ unit = self.UnitClass(source) self.addunit(unit) - return unit + return self.units[-1] def findunit(self, source): """Finds the unit with the given source string. Index: translate/storage/cpo.py =================================================================== --- translate/storage/cpo.py (revision 8018) +++ translate/storage/cpo.py (working copy) @@ -371,9 +371,18 @@ gpo.po_message_set_comments(self._gpo_message, "") def copy(self): - newpo = self.__class__() - newpo._gpo_message = self._gpo_message - return newpo + unit = self.buildfromunit(self) + #XXX: adding missing data + if self.isobsolete(): + unit.makeobsolete() + context = gpo.po_message_msgctxt(self._gpo_message) + if context: + unit.setcontext(context) + comments = self._extract_msgidcomments() + if comments: + print 'HAS COMMENTS', comments + unit.setmsgidcomment(comments) + return unit def merge(self, otherpo, overwrite=False, comments=True, authoritative=False): """Merges the otherpo (with the same msgid) into this one. @@ -476,7 +485,8 @@ def __str__(self): pf = pofile() - pf.addunit(self) + unit = self.copy() + pf.addunit(unit) return str(pf) def getlocations(self): @@ -505,6 +515,11 @@ line = -1 gpo.po_message_add_filepos(self._gpo_message, file, line) + def setcontext(self, context): + """Sets the context message""" + #FIXME: not complete + gpo.po_message_set_msgctxt(self._gpo_message, context) + def getcontext(self): msgctxt = gpo.po_message_msgctxt(self._gpo_message) msgidcomment = self._extract_msgidcomments() @@ -528,8 +543,9 @@ self._gpo_message_iterator = gpo.po_message_iterator(self._gpo_memory_file, None) def addunit(self, unit): - gpo.po_message_insert(self._gpo_message_iterator, unit._gpo_message) - self.units.append(unit) + unitcopy = unit.copy() + gpo.po_message_insert(self._gpo_message_iterator, unitcopy._gpo_message) + self.units.append(unitcopy) def removeduplicates(self, duplicatestyle="merge"): """make sure each msgid is unique ; merge comments etc from duplicates into original""" @@ -664,21 +680,23 @@ newunit = pounit(gpo_message=newmessage) self.units.append(newunit) newmessage = gpo.po_next_message(self._gpo_message_iterator) - self._free_iterator() + #self._free_iterator() def __del__(self): + #print 'DELL CALLED', id(self) # We currently disable this while we still get segmentation faults. # Note that this is definitely leaking memory because of this. - return + #return self._free_iterator() if self._gpo_memory_file is not None: gpo.po_file_free(self._gpo_memory_file) self._gpo_memory_file = None def _free_iterator(self): + #print 'ITERATOR CALLED', id(self) # We currently disable this while we still get segmentation faults. # Note that this is definitely leaking memory because of this. - return + #return if self._gpo_message_iterator is not None: gpo.po_message_iterator_free(self._gpo_message_iterator) self._gpo_message_iterator = None