コード例 #1
0
ファイル: translation.py プロジェクト: Gustry/qgis-plugin-ci
    def __init__(self,
                 parameters: Parameters,
                 transifex_token: str,
                 create_project: bool = True):
        """
        Parameters
        ----------
        parameters:

        transifex_token:
            Transifex API token

        create_project:
            if True, it will create the project, resource and language on Transifex

        """
        self.parameters = parameters
        self._t = Transifex(transifex_token,
                            parameters.transifex_organization,
                            i18n_type='QT')
        assert self._t.ping()
        self.ts_file = '{dir}/i18n/{res}_{lan}.ts'.format(
            dir=self.parameters.plugin_path,
            res=self.parameters.transifex_resource,
            lan=self.parameters.translation_source_language)

        if self._t.project_exists(parameters.transifex_project):
            print('Project {o}/{p} exists on Transifex'.format(
                o=self.parameters.transifex_organization,
                p=self.parameters.transifex_project))
        elif create_project:
            print(
                'project does not exists on Transifex, creating one as {o}/{p}'
                .format(o=self.parameters.transifex_organization,
                        p=self.parameters.transifex_project))
            self._t.create_project(
                slug=self.parameters.transifex_project,
                repository_url=self.parameters.repository_url,
                source_language_code=parameters.translation_source_language)
            self.update_strings()
            print('creating resource in {o}/{p}/{r} with {f}'.format(
                o=self.parameters.transifex_organization,
                p=self.parameters.transifex_project,
                r=self.parameters.transifex_resource,
                f=self.ts_file))
            self._t.create_resource(
                project_slug=self.parameters.transifex_project,
                path_to_file=self.ts_file,
                resource_slug=self.parameters.transifex_resource)
            print('OK')
        else:
            raise TranslationFailed(
                'Project {o}/{p} does not exists on Transifex'.format(
                    o=self.parameters.transifex_organization,
                    p=self.parameters.transifex_project))
コード例 #2
0
ファイル: translation.py プロジェクト: Gustry/qgis-plugin-ci
 def compile_strings(self):
     """
     Compile TS file into QM files
     """
     cmd = [self.parameters.lrelease_path]
     for file in glob.glob(
             '{dir}/i18n/*.ts'.format(dir=self.parameters.plugin_path)):
         cmd.append(file)
     output = subprocess.run(cmd, capture_output=True, text=True)
     if output.returncode != 0:
         raise TranslationFailed(output.stderr)
     else:
         print('Successfully run lrelease: {}'.format(output.stdout))
コード例 #3
0
ファイル: translation.py プロジェクト: phborba/qgis-plugin-ci
    def update_strings(self):
        """
        Update TS files from plugin source strings
        """
        source_py_files = []
        source_ui_files = []
        relative_path = "./{plugin_path}".format(
            plugin_path=self.parameters.plugin_path
        )
        for ext in ("py", "ui"):
            for file in glob.glob(
                "{dir}/**/*.{ext}".format(dir=self.parameters.plugin_path, ext=ext),
                recursive=True,
            ):
                file_path = str(Path(file).relative_to(relative_path))
                if ext == "py":
                    source_py_files.append(file_path)
                else:
                    source_ui_files.append(file_path)

        touch_file(self.ts_file)

        project_file = Path(self.parameters.plugin_path).joinpath(
            self.parameters.plugin_name + ".pro"
        )

        with open(project_file, "w") as f:
            assert f.write("CODECFORTR = UTF-8\n")
            assert f.write("SOURCES = {}\n".format(" ".join(source_py_files)))
            assert f.write("FORMS = {}\n".format(" ".join(source_ui_files)))
            assert f.write(
                "TRANSLATIONS = {}\n".format(
                    Path(self.ts_file).relative_to(relative_path)
                )
            )
            f.flush()
            f.close()

        cmd = [self.parameters.pylupdate5_path, "-noobsolete", str(project_file)]

        output = subprocess.run(cmd, capture_output=True, text=True)

        project_file.unlink()

        if output.returncode != 0:
            raise TranslationFailed(output.stderr)
        else:
            print("Successfully run pylupdate5: {}".format(output.stdout))
コード例 #4
0
 def update_strings(self):
     """
     Update TS files from plugin source strings
     """
     cmd = [self.parameters.pylupdate5_path, '-noobsolete']
     for ext in ('py', 'ui'):
         for file in glob.glob('{dir}/**/*.{ext}'.format(
                 dir=self.parameters.plugin_path, ext=ext),
                               recursive=True):
             cmd.append(file)
     touch_file(self.ts_file)
     cmd.append('-ts')
     cmd.append(self.ts_file)
     output = subprocess.run(cmd, capture_output=True, text=True)
     if output.returncode != 0:
         raise TranslationFailed(output.stderr)
     else:
         print('Successfully run pylupdate5: {}'.format(output.stdout))
コード例 #5
0
ファイル: translation.py プロジェクト: Gustry/qgis-plugin-ci
    def update_strings(self):
        """
        Update TS files from plugin source strings
        """
        source_files = []
        relative_path = './{plugin_path}'.format(
            plugin_path=self.parameters.plugin_path)
        for ext in ('py', 'ui'):
            for file in glob.glob('{dir}/**/*.{ext}'.format(
                    dir=self.parameters.plugin_path, ext=ext),
                                  recursive=True):
                source_files.append(str(Path(file).relative_to(relative_path)))

        touch_file(self.ts_file)

        project_file = Path(
            self.parameters.plugin_path).joinpath(self.parameters.plugin_name +
                                                  '.pro')

        with open(project_file, 'w') as f:
            assert f.write('CODECFORTR = UTF-8\n')
            assert f.write('SOURCES = {}\n'.format(' '.join(source_files)))
            assert f.write('TRANSLATIONS = {}\n'.format(
                Path(self.ts_file).relative_to(relative_path)))
            f.flush()
            f.close()

        cmd = [
            self.parameters.pylupdate5_path, '-noobsolete',
            str(project_file)
        ]

        output = subprocess.run(cmd, capture_output=True, text=True)

        project_file.unlink()

        if output.returncode != 0:
            raise TranslationFailed(output.stderr)
        else:
            print('Successfully run pylupdate5: {}'.format(output.stdout))