feat: Push local strings into traduora if writable secrets are set.
This commit is contained in:
parent
9e2e09e5fd
commit
f76bb2ab2a
@ -6,10 +6,7 @@ steps:
|
||||
- name: build
|
||||
image: node
|
||||
commands:
|
||||
- cd web
|
||||
- npm install
|
||||
- npm run build
|
||||
- cd ..
|
||||
- (cd web && npm install && npm run build)
|
||||
|
||||
- name: deploy-testing
|
||||
image: debian
|
||||
@ -20,7 +17,7 @@ steps:
|
||||
- echo "current git commit is $version"
|
||||
- echo $version > /mnt/botamusique/testing-version
|
||||
- sed -i "s/version = 'git'/version = '$version'/" mumbleBot.py
|
||||
- ./lang/translate.py
|
||||
- (cd lang && ./sync_translation.py)
|
||||
- rm -rf .git*
|
||||
- rm -rf web
|
||||
- mkdir /tmp/botamusique
|
||||
@ -62,6 +59,7 @@ steps:
|
||||
- echo $version > /mnt/botamusique/version
|
||||
- sed -i "s/version = 'git'/version = '$version'/" mumbleBot.py
|
||||
- curl --silent "https://api.github.com/repos/azlux/botamusique/releases/latest" | jq -r '.body' | pandoc --from gfm --to html - --output - > /mnt/botamusique/changelog
|
||||
- (cd lang && ./sync_translation.py)
|
||||
- rm -rf .git*
|
||||
- rm -rf web
|
||||
- mkdir /tmp/botamusique
|
||||
|
64
lang/sync_translation.py
Executable file
64
lang/sync_translation.py
Executable file
@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import requests
|
||||
|
||||
base_url = "https://translate.azlux.fr/api/v1"
|
||||
project_id = "4aafb197-3282-47b3-a197-0ca870cf6ab2"
|
||||
r_client = "be8215d4-2417-49db-9355-c418f26dc3f4"
|
||||
r_secret = "MIMvdnECLkmTZyCQT4DekONN53EOSsj3"
|
||||
w_client = os.environ.get("TRADUORA_W_CLIENT", default=None)
|
||||
w_secret = os.environ.get("TRADUORA_W_SECRET", default=None)
|
||||
|
||||
|
||||
def fetch_translation():
|
||||
print("Fetching translation from remote host...")
|
||||
data = {"grant_type": "client_credentials",
|
||||
"client_id": r_client,
|
||||
"client_secret": r_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']
|
||||
print(f" - Fetching {lang_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)
|
||||
|
||||
|
||||
def push_strings():
|
||||
print("Pushing local en_US file into the remote host...")
|
||||
data = {"grant_type": "client_credentials",
|
||||
"client_id": w_client,
|
||||
"client_secret": w_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, */*"}
|
||||
|
||||
params = {'locale': 'en_US',
|
||||
'format': 'jsonnested'}
|
||||
|
||||
files = {'file': open('lang/en_US', 'r')}
|
||||
r = requests.post(f"{base_url}/projects/{project_id}/exports", data=params, headers=headers, files=files)
|
||||
assert r.status_code == 200, "Unable to push local en_US file into remote host."
|
||||
|
||||
|
||||
if w_client and w_secret:
|
||||
print("Detected writable API keys from environ.")
|
||||
push_strings()
|
||||
|
||||
fetch_translation()
|
||||
|
||||
print("Done.")
|
@ -1,28 +0,0 @@
|
||||
#!/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)
|
Loading…
x
Reference in New Issue
Block a user