Beispiel #1
0
    def run(self):
        if not os.path.exists(self.sync.filepath):
            os.makedirs(self.sync.filepath)

        url = "https://platform.api.onesky.io/1/projects/{}/translations".format(
            self.sync.project)

        auth = authentication_details(self.sync.api_key, self.sync.api_secret)
        params = {
            "source_file_name": "{}.json".format(self.sync.base),
            "locale": self.lang,
            "export_file_name": "{}.json".format(self.lang)
        }
        for key in auth.keys():
            params[key] = auth[key]

        data = requests.get(url, params=params).content.decode()
        if data:
            if self.sync.rename:
                json_path = "{}/{}.json".format(self.sync.filepath,
                                                self.lang.replace("-", "_"))
            else:
                json_path = "{}/{}.json".format(self.sync.filepath, self.lang)

            with open(json_path, "w+") as new_json_file:
                new_json_file.write(data)

            print("{}.json downloaded and saved to {}".format(
                self.lang, json_path))
        else:
            print("{}.json not downloaded - No data to download".format(
                self.lang))

        return
Beispiel #2
0
    def get_languages(self):
        """
        Gets the list of the languages for the specified project
        :return: List
        """
        url = "https://platform.api.onesky.io/1/projects/{}/languages".format(
            self.project)
        data = requests.get(url,
                            params=authentication_details(
                                self.api_key, self.api_secret)).json()
        langs = []

        if "error" in data.keys():
            print('Error from OneSky:')
            print(data["error"])
            sys.exit(1)

        for lang in data["data"]:
            langs.append(lang["code"])
        if self.exclude:
            for lang in self.exclude:
                try:
                    langs.remove(lang)
                except ValueError:
                    pass

        return langs
Beispiel #3
0
    def upload(self):
        print("Compiling data to upload")
        url = "https://platform.api.onesky.io/1/projects/{0}/files".format(
            self.project)
        print("Attempting to upload file located at {0}".format(self.filepath))
        try:
            files = {'file': open(self.filepath, 'rb')}
            payload = authentication_details(self.api_key, self.api_secret)
            payload['file_format'] = self.file_type
            payload['locale'] = self.base
            payload["is_keeping_all_strings"] = self.keep
            payload["is_keeping_all_strings"] = "false"

            print("Data compiled... uploading!")
            res = requests.post(url, files=files, params=payload)
            if res.json()['meta']['status'] == 201:
                print("Succesfully uploaded!")
            else:
                print("Something went wrong...")
                print(json.dumps(res.json(), indent=4))

            return
        except FileNotFoundError:
            print("No file located at {0} - Please give a valid file path".
                  format(self.filepath))
            sys.exit(2)
Beispiel #4
0
    def run(self):
        if not os.path.exists(self.sync.langpath):
            os.makedirs(self.sync.langpath)

        url = "https://platform.api.onesky.io/1/projects/{}/translations".format(
            self.sync.project)

        auth = authentication_details(self.sync.api_key, self.sync.api_secret)
        params = {
            "source_file_name": "{}.po".format(self.sync.base),
            "locale": self.lang,
            "export_file_name": "{}.po".format(self.lang)
        }
        for key in auth.keys():
            params[key] = auth[key]

        data = requests.get(url, params=params).content.decode()

        if self.sync.rename:
            po_path = "{}/{}.po".format(self.sync.langpath,
                                        self.lang.replace("-", "_"))
            mo_path = "{}/{}.mo".format(self.sync.filepath,
                                        self.lang.replace("-", "_"))
        else:
            po_path = "{}/{}.po".format(self.sync.langpath, self.lang)
            mo_path = "{}/{}.mo".format(self.sync.filepath, self.lang)

        with open(po_path, "w+") as po_file:
            po_file.write(data)

        po = polib.pofile(po_path)
        print("{}.po downloaded and saved to {}, converting to MO".format(
            self.lang, po_path))

        po.save_as_mofile(mo_path)
        print("{}.mo converted and saved to {}".format(self.lang, mo_path))

        if not self.sync.keep:
            print("Deleing PO files")
            shutil.rmtree(self.sync.langpath)

        return