Discover translation files in git systems

Julien LepillerFri Aug 23 14:40:35+0200 2019

57b6668

Discover translation files in git systems

offlate/systems/git.py

1818
import pygit2
1919
from os import rename, remove
2020
21+
from translation_finder import discover
22+
from ..formats.yaml import YamlFormat
23+
from ..formats.gettext import GettextFormat
24+
2125
class Progress(pygit2.remote.RemoteCallbacks):
2226
    def __init__(self, callback):
2327
        super().__init__()

5155
5256
    def updateFiles(self):
5357
        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']))
5481
5582
    def clone(self, directory, callback=None):
5683
        pygit2.clone_repository(self.uri, directory, callbacks=Progress(callback))

7299
        pass
73100
74101
    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

6060
            return
6161
        actions = []
6262
        for mfile in self.translationfiles:
63+
            mfile = mfile['filename']
6364
            try:
6465
                project.files.get(file_path=mfile, ref=self.branch)
6566
                actions.append({'action': 'update',