feat: Load language file in lang/ instead of the ini file.

This commit is contained in:
Terry Geng
2020-07-11 11:01:33 +08:00
parent e84607b8e8
commit 9e2e09e5fd
12 changed files with 123 additions and 217 deletions

28
lang/translate.py Normal file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env python3
import requests
base_url = "https://translate.azlux.fr/api/v1"
client = "be8215d4-2417-49db-9355-c418f26dc3f4"
secret = "MIMvdnECLkmTZyCQT4DekONN53EOSsj3"
project_id = "4aafb197-3282-47b3-a197-0ca870cf6ab2"
data = {"grant_type": "client_credentials",
"client_id": client,
"client_secret": secret}
r = requests.post(f"{base_url}/auth/token", json=data)
token = r.json()["access_token"]
headers = {"Authorization": "Bearer " + token,
"Accept": "application/json, text/plain, */*"}
r = requests.get(f"{base_url}/projects/{project_id}/translations", headers=headers)
translations = r.json()['data']
for translation in translations:
lang_code = translation['locale']['code']
params = {'locale': lang_code,
'format': 'jsonnested'}
r = requests.get(f"{base_url}/projects/{project_id}/exports", params=params, headers=headers)
with open(lang_code, "wb")as f:
f.write(r.content)