Index: translate/storage/cpo.py =================================================================== --- translate/storage/cpo.py (revision 8029) +++ translate/storage/cpo.py (working copy) @@ -371,9 +371,32 @@ gpo.po_message_set_comments(self._gpo_message, "") def copy(self): - newpo = self.__class__() - newpo._gpo_message = self._gpo_message - return newpo + """Returns a copy of the this unit that can be used independently. + """ + unit = pounit() + unit.source = self.source + unit.target = self.target + unit.markfuzzy(self.isfuzzy()) + if self.isobsolete(): + unit.makeobsolete() + for location in self.getlocations(): + unit.addlocation(location) + notes = [] + origins = ['translator', 'developer', 'programmer', 'source code'] + for origin in origins: + note = self.getnotes(origin=origin) + if note in notes: + continue + if note: + unit.addnote(note, origin=origin) + notes.append(note) + context = gpo.po_message_msgctxt(self._gpo_message) + if context: + unit.setcontext(context) + comments = self._extract_msgidcomments() + if 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 +499,8 @@ def __str__(self): pf = pofile() - pf.addunit(self) + unit = self.copy() + pf.addunit(unit) return str(pf) def getlocations(self): @@ -505,6 +529,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 +557,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,12 +694,10 @@ newunit = pounit(gpo_message=newmessage) self.units.append(newunit) newmessage = gpo.po_next_message(self._gpo_message_iterator) - self._free_iterator() def __del__(self): # We currently disable this while we still get segmentation faults. # Note that this is definitely leaking memory because of this. - return self._free_iterator() if self._gpo_memory_file is not None: gpo.po_file_free(self._gpo_memory_file) @@ -678,7 +706,6 @@ def _free_iterator(self): # We currently disable this while we still get segmentation faults. # Note that this is definitely leaking memory because of this. - return if self._gpo_message_iterator is not None: gpo.po_message_iterator_free(self._gpo_message_iterator) self._gpo_message_iterator = None Index: translate/storage/base.py =================================================================== --- translate/storage/base.py (revision 8029) +++ translate/storage/base.py (working copy) @@ -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.