Discover translation files in git systems
offlate/systems/git.py
| 18 | 18 | import pygit2 | |
| 19 | 19 | from os import rename, remove | |
| 20 | 20 | ||
| 21 | + | from translation_finder import discover | |
| 22 | + | from ..formats.yaml import YamlFormat | |
| 23 | + | from ..formats.gettext import GettextFormat | |
| 24 | + | ||
| 21 | 25 | class Progress(pygit2.remote.RemoteCallbacks): | |
| 22 | 26 | def __init__(self, callback): | |
| 23 | 27 | super().__init__() | |
… | |||
| 51 | 55 | ||
| 52 | 56 | def updateFiles(self): | |
| 53 | 57 | self.translationfiles = [] | |
| 58 | + | translations = discover(self.basedir + '/current') | |
| 59 | + | path = self.basedir + '/current/' | |
| 60 | + | for resource in translations: | |
| 61 | + | if resource['file_format'] == 'po': | |
| 62 | + | popath = resource['filemask'].replace('*', self.lang) | |
| 63 | + | if 'new_base' in resource: | |
| 64 | + | potpath = resource['newbase'] | |
| 65 | + | else: | |
| 66 | + | # If there is no POT, then we can't really do anything... | |
| 67 | + | continue | |
| 68 | + | self.translationfiles.append({'filename': popath, | |
| 69 | + | 'format': GettextFormat({'file': path + popath, | |
| 70 | + | 'pot': path + potpath, | |
| 71 | + | 'version': '0.1', | |
| 72 | + | 'fullname': self.conf['fullname'], | |
| 73 | + | 'lang': self.lang})}) | |
| 74 | + | elif resource['file_format'] == 'yaml': | |
| 75 | + | yamlpath = resource['filemask'].replace('*', self.lang) | |
| 76 | + | self.translationfiles.append({'filename': yamlpath, | |
| 77 | + | 'format': YamlFormat({'dest': path + yamlpath, | |
| 78 | + | 'source': path + resource['template']})}) | |
| 79 | + | else: | |
| 80 | + | raise Exception('Unsupported file format: {}'.format(resource['file_format'])) | |
| 54 | 81 | ||
| 55 | 82 | def clone(self, directory, callback=None): | |
| 56 | 83 | pygit2.clone_repository(self.uri, directory, callbacks=Progress(callback)) | |
… | |||
| 72 | 99 | pass | |
| 73 | 100 | ||
| 74 | 101 | def content(self): | |
| 75 | - | return {'default': []} | |
| 102 | + | content = {} | |
| 103 | + | for resource in self.translationfiles: | |
| 104 | + | content[resource['filename']] = resource['format'].content() | |
| 105 | + | return content | |
offlate/systems/gitlab.py
| 60 | 60 | return | |
| 61 | 61 | actions = [] | |
| 62 | 62 | for mfile in self.translationfiles: | |
| 63 | + | mfile = mfile['filename'] | |
| 63 | 64 | try: | |
| 64 | 65 | project.files.get(file_path=mfile, ref=self.branch) | |
| 65 | 66 | actions.append({'action': 'update', |