Commit e8ce2bda authored by Sascha Pfeiffer's avatar Sascha Pfeiffer

automated language sync with poeditor

Signed-off-by: default avatarSascha Pfeiffer <sascha.pfeiffer@psono.com>
parent bac09236
......@@ -34,14 +34,14 @@ test-linter:
- addons-linter ./build/firefox
#test-translation-terms:
# stage: build
# image: psono-docker.jfrog.io/ubuntu:16.04
# script:
# - sh ./var/build-ubuntu.sh
# - curl -X POST https://api.poeditor.com/v2/projects/upload -F api_token=$POEDITOR_API_KEY -F id="198999" -F updating="terms" -F file=@"src/common/data/translations/terms.json"
# only:
# - develop
test-upload-translations:
stage: build
image: psono-docker.jfrog.io/python:3
script:
- pip install requests
- python3 var/sync_translations.py
only:
- develop
build-docker-image:
......@@ -54,6 +54,7 @@ build-docker-image:
variables:
DOCKER_HOST: 'tcp://docker:2375'
script:
- sh ./var/download_translations_from_artifactory.sh
- sh ./var/build-ubuntu.sh
- curl -fSL "https://download.docker.com/linux/static/stable/x86_64/docker-17.12.1-ce.tgz" -o docker.tgz && echo "1270dce1bd7e1838d62ae21d2505d87f16efc1d9074645571daaefdfd0c14054 *docker.tgz" | sha256sum -c - && tar -xzvf docker.tgz && mv docker/* /usr/local/bin/ && rm -Rf docker*
- docker info
......@@ -73,6 +74,7 @@ build-firefox-extension:
stage: build
image: psono-docker.jfrog.io/ubuntu:16.04
script:
- sh ./var/download_translations_from_artifactory.sh
- sh ./var/build-ubuntu.sh
- sh ./var/package-firefox-extension.sh
- curl -fL https://getcli.jfrog.io | sh
......@@ -95,6 +97,7 @@ build-chrome-extension:
stage: build
image: psono-docker.jfrog.io/ubuntu:16.04
script:
- sh ./var/download_translations_from_artifactory.sh
- sh ./var/build-ubuntu.sh
- sh ./var/package-chrome-extension.sh
- curl -fL https://getcli.jfrog.io | sh
......@@ -117,6 +120,7 @@ build-webclient:
stage: build
image: psono-docker.jfrog.io/ubuntu:16.04
script:
- sh ./var/download_translations_from_artifactory.sh
- sh ./var/build-ubuntu.sh
- sh ./var/package-webclient.sh
- curl -fL https://getcli.jfrog.io | sh
......
#!/usr/bin/env bash
apt-get update && \
apt-get install -y curl && \
curl -o src/common/data/translations/locale-de.json https://psono.jfrog.io/psono/psono/client/languages/locale-de.json && \
curl -o src/common/data/translations/locale-en.json https://psono.jfrog.io/psono/psono/client/languages/locale-en.json
import requests
import shutil
import os
POEDITOR_API_KEY = os.environ['POEDITOR_API_KEY']
POEDITOR_PROJECT_ID = os.environ['POEDITOR_PROJECT_ID']
ARTIFACTORY_URL = os.environ.get('ARTIFACTORY_URL', 'https://psono.jfrog.io/psono')
ARTIFACTORY_PATH = os.environ.get('ARTIFACTORY_PATH', '/psono/client/languages/')
ARTIFACTORY_USER = os.environ.get('ARTIFACTORY_USER', 'gitlab')
ARTIFACTORY_PASS = os.environ['ARTIFACTORY_PASS']
LANGUAGE_CODES = [
"af", "sq", "ar_SA", "ar_IQ", "ar_EG", "ar_LY", "ar_DZ", "ar_MA", "ar_TN", "ar_OM",
"ar_YE", "ar_SY", "ar_JO", "ar_LB", "ar_KW", "ar_AE", "ar_BH", "ar_QA", "eu", "bg",
"be", "ca", "zh_TW", "zh_CN", "zh_HK", "zh_SG", "hr", "cs", "da", "nl", "nl_BE", "en",
"en_US", "en_EG", "en_AU", "en_GB", "en_CA", "en_NZ", "en_IE", "en_ZA", "en_JM",
"en_BZ", "en_TT", "et", "fo", "fa", "fi", "fr", "fr_BE", "fr_CA", "fr_CH", "fr_LU",
"gd", "gd_IE", "de", "de_CH", "de_AT", "de_LU", "de_LI", "el", "he", "hi", "hu",
"is", "id", "it", "it_CH", "ja", "ko", "lv", "lt", "mk", "mt", "no", "pl",
"pt_BR", "pt", "rm", "ro", "ro_MO", "ru", "ru_MI", "sz", "sr", "sk", "sl", "sb",
"es", "es_AR", "es_GT", "es_CR", "es_PA", "es_DO", "es_MX", "es_VE", "es_CO",
"es_PE", "es_EC", "es_CL", "es_UY", "es_PY", "es_BO", "es_SV", "es_HN", "es_NI",
"es_PR", "sx", "sv", "sv_FI", "th", "ts", "tn", "tr", "uk", "ur", "ve", "vi", "xh",
"ji", "zu"
]
def upload_language(lang):
params = (
('api_token', POEDITOR_API_KEY),
('id_project', POEDITOR_PROJECT_ID),
('language', lang),
('operation', 'import_terms_and_translations'),
)
r = requests.post('https://poeditor.com/api/webhooks/gitlab', params=params)
if not r.ok or r.text != 'Request received':
print("Error: upload_language")
print(r.json())
exit(1)
def download_language(lang):
data = [
('api_token', POEDITOR_API_KEY),
('action', 'export'),
('id', POEDITOR_PROJECT_ID),
('language', lang),
('type', 'key_value_json'),
]
r = requests.post('https://poeditor.com/api/', data=data)
if not r.ok:
print("Error: download_language")
print(r.json())
exit(1)
result = r.json()
r = requests.get(result['item'], stream=True)
path = 'locale-'+lang+'.json'
if r.status_code == 200:
with open(path, 'wb') as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
return path
def deploy_to_artifactory(artifactory_user, artifactory_pass, artifactory_url, path, file):
with open(file, 'rb') as f:
r = requests.put(artifactory_url + path + file,
data=f,
auth=(artifactory_user, artifactory_pass))
if not r.ok:
print("Error: get_languages")
print(r.json())
exit(1)
result = r.json()
print(result)
def get_languages():
data = [
('api_token', POEDITOR_API_KEY),
('id', POEDITOR_PROJECT_ID),
]
r = requests.post('https://api.poeditor.com/v2/languages/list', data=data)
if not r.ok:
print("Error: get_languages")
print(r.json())
exit(1)
result = r.json()
return result['result']['languages']
def main():
languages = get_languages()
for lang in languages:
if lang['code'] not in LANGUAGE_CODES:
print("Error: main")
print("Invalid Language Code " + lang['code'])
exit(1)
upload_language(lang['code'])
file = download_language(lang['code'])
deploy_to_artifactory(ARTIFACTORY_USER, ARTIFACTORY_PASS, ARTIFACTORY_URL, ARTIFACTORY_PATH, file)
print("Success")
if __name__ == "__main__":
main()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment