Add update and send methods to transifex system
offlate/formats/yaml.py
| 74 | 74 | f.write(yaml.dump(data, allow_unicode=True, Dumper=yaml.RoundTripDumper).encode('utf8')) | |
| 75 | 75 | ||
| 76 | 76 | def merge(self, older, callback): | |
| 77 | - | pass | |
| 77 | + | with open(older.dest, 'rb') as oldf: | |
| 78 | + | with open(self.dest, 'rb') as newf: | |
| 79 | + | with open(self.source, 'rb') as sourcef: | |
| 80 | + | old = yaml.safe_load(oldf) | |
| 81 | + | new = yaml.safe_load(newf) | |
| 82 | + | source = yaml.safe_load(sourcef) | |
| 83 | + | merged = yaml_rec_update(callback, source, old, new) | |
| 84 | + | with open(self.dest, 'wb') as f: | |
| 85 | + | f.write(yaml.dump(merged, allow_unicode=True, Dumper=yaml.RoundTripDumper).encode('utf8')) |
offlate/systems/transifex.py
| 55 | 55 | currentformat = YamlFormat({'dest': fname, 'source': sname}) | |
| 56 | 56 | else: | |
| 57 | 57 | raise Exception("Unsupported format: " + ff['i18n_type']) | |
| 58 | - | currentformat.merge(oldformat) | |
| 58 | + | currentformat.merge(oldformat, callback) | |
| 59 | 59 | ||
| 60 | 60 | def filename(self, slug, is_source): | |
| 61 | 61 | ext = '' | |
… | |||
| 87 | 87 | print(ans.text) | |
| 88 | 88 | ||
| 89 | 89 | def send(self, interface): | |
| 90 | - | pass | |
| 90 | + | self.save() | |
| 91 | + | for slug in self.files: | |
| 92 | + | print('{} => {}'.format(slug['slug'], slug['i18n_type'])) | |
| 93 | + | with open(self.filename(slug['slug'], False), 'rb') as f: | |
| 94 | + | content = f.read() | |
| 95 | + | sendcontent = {"content": content.decode('utf8')} | |
| 96 | + | ans = requests.put('https://www.transifex.com/api/2/project/'+ | |
| 97 | + | self.name+'/resource/'+slug['slug']+'/translation/'+self.lang+'/', | |
| 98 | + | json=sendcontent, auth=HTTPBasicAuth('api', self.conf['token'])) | |
| 99 | + | print(ans) | |
| 100 | + | print(ans.text) | |
| 91 | 101 | ||
| 92 | 102 | def save(self): | |
| 93 | - | for slug in self.content: | |
| 103 | + | for slug in self.slugs: | |
| 94 | 104 | slug.save() | |
| 95 | 105 | ||
| 96 | 106 | def content(self): | |
| 97 | 107 | content = {} | |
| 98 | - | self.content = [] | |
| 108 | + | self.slugs = [] | |
| 99 | 109 | for slug in self.files: | |
| 100 | 110 | if slug['i18n_type'] == 'YML': | |
| 101 | 111 | myslug = YamlFormat( | |
… | |||
| 103 | 113 | 'source': self.filename(slug['slug'], True)}) | |
| 104 | 114 | else: | |
| 105 | 115 | raise Exception("Unsupported format: " + slug['i18n_type']) | |
| 106 | - | self.content.append(myslug) | |
| 116 | + | self.slugs.append(myslug) | |
| 107 | 117 | content[slug['slug']] = myslug.content() | |
| 108 | 118 | return content | |