Fix weblate upload
offlate/systems/weblate.py
| 55 | 55 | def updateFileList(self): | |
| 56 | 56 | self.files = [] | |
| 57 | 57 | ans = requests.get(self.data['instance'] + '/api/projects/' + | |
| 58 | - | self.data['project'] + '/components', | |
| 58 | + | self.data['project'] + '/components/', | |
| 59 | 59 | auth=HTTPBasicAuth('Token', self.conf['token'])) | |
| 60 | 60 | if ans.status_code == 200: | |
| 61 | - | l = json.loads(ans.text)['results'] | |
| 61 | + | l = list(filter(lambda x: x['is_glossary'] == False, json.loads(ans.text)['results'])) | |
| 62 | 62 | self.files = l | |
| 63 | 63 | else: | |
| 64 | 64 | print(ans.text) | |
… | |||
| 117 | 117 | source_lang = l['source_language']['code'] | |
| 118 | 118 | ||
| 119 | 119 | ans = requests.get(self.data['instance'] + '/api/translations/' + | |
| 120 | - | self.data['project'] + '/' + slug + '/' + self.lang + '/file', | |
| 120 | + | self.data['project'] + '/' + slug + '/' + self.lang + '/file/', | |
| 121 | 121 | auth=HTTPBasicAuth('Token', self.conf['token'])) | |
| 122 | 122 | encoding = ans.encoding if ans.encoding is not None else 'utf-8' | |
| 123 | 123 | if ans.status_code == 200: | |
… | |||
| 125 | 125 | f.write(ans.text.encode(encoding)) | |
| 126 | 126 | ||
| 127 | 127 | ans = requests.get(self.data['instance'] + '/api/translations/' + | |
| 128 | - | self.data['project'] + '/' + slug + '/' + source_lang + '/file', | |
| 128 | + | self.data['project'] + '/' + slug + '/' + source_lang + '/file/', | |
| 129 | 129 | auth=HTTPBasicAuth('Token', self.conf['token'])) | |
| 130 | 130 | encoding = ans.encoding if ans.encoding is not None else 'utf-8' | |
| 131 | 131 | if ans.status_code == 200: | |
… | |||
| 146 | 146 | self.data['project'] + '/' + slug['slug'] + '/' + | |
| 147 | 147 | self.lang + '/file/', | |
| 148 | 148 | files={'file': (os.path.basename(filename), open(filename, 'rb'))}, | |
| 149 | - | #data={'conflicts': 'replace-translated', | |
| 150 | - | # 'method': 'translate'}, | |
| 151 | - | auth=HTTPBasicAuth('Token', self.conf['token'])) | |
| 149 | + | headers={"user-agent": "offlate", "Accept": "application/json", | |
| 150 | + | "Authorization": 'Token '+self.conf['token']}, | |
| 151 | + | data={'conflicts': 'replace-translated', | |
| 152 | + | 'method': 'translate'}) | |
| 153 | + | #auth=HTTPBasicAuth('Token', self.conf['token'])) | |
| 152 | 154 | print(ans) | |
| 153 | 155 | print(ans.text) | |
| 154 | 156 | i += 1 | |
… | |||
| 172 | 174 | 'lang': self.lang}) | |
| 173 | 175 | else: | |
| 174 | 176 | raise UnsupportedFormatException(ff['file_format']) | |
| 177 | + | ||
| 175 | 178 | self.slugs.append(myslug) | |
| 176 | 179 | content[slug['slug']] = myslug.content() | |
| 177 | 180 | return content | |