Implement merge in ts format
offlate/formats/ts.py
25 | 25 | self.tsfilename = conf["file"] | |
26 | 26 | self.tscontent = self.parse(self.tsfilename) | |
27 | 27 | self.conf = conf | |
28 | - | self.savedcontent = None | |
28 | + | self.savedcontent = [TSEntry(x) for x in self.tscontent] | |
29 | 29 | ||
30 | 30 | def parse(self, filename): | |
31 | 31 | result = [] | |
… | |||
41 | 41 | return result | |
42 | 42 | ||
43 | 43 | def content(self): | |
44 | - | if self.savedcontent is None: | |
45 | - | self.savedcontent = [TSEntry(x) for x in self.tscontent] | |
46 | 44 | return self.savedcontent | |
47 | 45 | ||
48 | 46 | def save(self): | |
… | |||
81 | 79 | f.write(ET.tostring(root).decode("utf-8")) | |
82 | 80 | ||
83 | 81 | 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 |