Implement merge in ts format

Julien LepillerSat Aug 24 21:50:32+0200 2019

624f5eb

Implement merge in ts format

offlate/formats/ts.py

2525
        self.tsfilename = conf["file"]
2626
        self.tscontent = self.parse(self.tsfilename)
2727
        self.conf = conf
28-
        self.savedcontent = None
28+
        self.savedcontent = [TSEntry(x) for x in self.tscontent]
2929
3030
    def parse(self, filename):
3131
        result = []

4141
        return result
4242
4343
    def content(self):
44-
        if self.savedcontent is None:
45-
            self.savedcontent = [TSEntry(x) for x in self.tscontent]
4644
        return self.savedcontent
4745
4846
    def save(self):

8179
            f.write(ET.tostring(root).decode("utf-8"))
8280
8381
    def merge(self, older, callback):
84-
        pass
85-
82+
        for entry in self.savedcontent:
83+
            for oentry in older.savedcontent:
84+
                if oentry.msgids[0] == entry.msgids[0]:
85+
                    if len(oentry.msgstrs) == len(entry.msgstrs):
86+
                        for i in range(0, len(oentry.msgstrs)):
87+
                            if entry.msgstrs[i] == '' or \
88+
                                    entry.msgstrs[i] == oentry.msgstrs[i]:
89+
                                entry.update(i, oentry.msgstrs[i])
90+
                            elif oentry.msgstrs[i] == '':
91+
                                break
92+
                            else:
93+
                                entry.update(i, callback(entry.msgids[0],
94+
                                    oentry.msgstrs[i], entry.msgstrs[i]))
95+
                    break