Crowdin integration full (#13171)
* Create crowdin-daily.yml * Update crowdin.yaml * Update crowdin_sync.py * Update fetch_progress.py
This commit is contained in:
parent
cbfbd14268
commit
6ad91b2b37
|
@ -0,0 +1,32 @@
|
||||||
|
# Download translations from Crowdin and push to GitHub
|
||||||
|
|
||||||
|
name: Crowdin Daily Workflow
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * *' # every day at midnight
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sync:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Setup Java JDK
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: 1.8
|
||||||
|
- name: Setup Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Crowdin Sync
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
CROWDIN_API_KEY: ${{ secrets.CROWDIN_API_KEY }}
|
||||||
|
run: |
|
||||||
|
cd intl
|
||||||
|
python3 crowdin_sync.py "$CROWDIN_API_KEY"
|
||||||
|
git config user.name github-actions
|
||||||
|
git config user.email github-actions@github.com
|
||||||
|
git add .
|
||||||
|
git commit -m "Fetch translations from Crowdin"
|
||||||
|
git push
|
|
@ -1,5 +1,6 @@
|
||||||
"project_identifier": "retroarch"
|
"project_id": "380544"
|
||||||
"api_key": "_secret_"
|
"api_token": "_secret_"
|
||||||
|
"base_url": "https://api.crowdin.com"
|
||||||
"preserve_hierarchy": true
|
"preserve_hierarchy": true
|
||||||
|
|
||||||
"files":
|
"files":
|
||||||
|
|
|
@ -32,7 +32,7 @@ jar_name = 'crowdin-cli.jar'
|
||||||
if not os.path.isfile(jar_name):
|
if not os.path.isfile(jar_name):
|
||||||
print('download crowdin-cli.jar')
|
print('download crowdin-cli.jar')
|
||||||
crowdin_cli_file = 'crowdin-cli.zip'
|
crowdin_cli_file = 'crowdin-cli.zip'
|
||||||
crowdin_cli_url = 'https://downloads.crowdin.com/cli/v2/' + crowdin_cli_file
|
crowdin_cli_url = 'https://downloads.crowdin.com/cli/v3/' + crowdin_cli_file
|
||||||
urllib.request.urlretrieve(crowdin_cli_url, crowdin_cli_file)
|
urllib.request.urlretrieve(crowdin_cli_url, crowdin_cli_file)
|
||||||
with zipfile.ZipFile(crowdin_cli_file, 'r') as zip_ref:
|
with zipfile.ZipFile(crowdin_cli_file, 'r') as zip_ref:
|
||||||
jar_dir = zip_ref.namelist()[0]
|
jar_dir = zip_ref.namelist()[0]
|
||||||
|
@ -56,7 +56,7 @@ print('wait for crowdin server to process data')
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
print('download translation *.json')
|
print('download translation *.json')
|
||||||
subprocess.run(['java', '-jar', 'crowdin-cli.jar', 'download', 'translations'])
|
subprocess.run(['java', '-jar', 'crowdin-cli.jar', 'download'])
|
||||||
|
|
||||||
print('convert *.json to *.h')
|
print('convert *.json to *.h')
|
||||||
for file in os.listdir(dir_path):
|
for file in os.listdir(dir_path):
|
||||||
|
|
|
@ -6,12 +6,20 @@ import yaml
|
||||||
|
|
||||||
with open("crowdin.yaml", 'r') as config_file:
|
with open("crowdin.yaml", 'r') as config_file:
|
||||||
config = yaml.safe_load(config_file)
|
config = yaml.safe_load(config_file)
|
||||||
r = requests.get('https://api.crowdin.com/api/project/' + config['project_identifier'] + '/status?key=' + config['api_key'] + '&json')
|
headers = { 'Authorization': 'Bearer ' + config['api_token']}
|
||||||
|
|
||||||
|
url1 = 'https://api.crowdin.com/api/v2/projects/' + config['project_id'] + '/languages/progress?limit=100'
|
||||||
|
res1 = requests.get(url1, headers=headers)
|
||||||
output = ''
|
output = ''
|
||||||
for lang in r.json():
|
for lang in res1.json()['data']:
|
||||||
output += '/* ' + lang['name'] + ' */\n'
|
lang_id = lang['data']['languageId']
|
||||||
escaped_name = lang['name'].replace(', ', '_').replace(' ', '_').upper()
|
url2 = 'https://api.crowdin.com/api/v2/languages/' + lang_id
|
||||||
output += '#define LANGUAGE_PROGRESS_' + escaped_name + '_TRANSLATED ' + str(lang['translated_progress']) + '\n'
|
res2 = requests.get(url2, headers=headers)
|
||||||
output += '#define LANGUAGE_PROGRESS_' + escaped_name + '_APPROVED ' + str(lang['approved_progress']) + '\n\n'
|
lang_name = res2.json()['data']['name']
|
||||||
|
|
||||||
|
output += '/* ' + lang_name + ' */\n'
|
||||||
|
escaped_name = lang_name.replace(', ', '_').replace(' ', '_').upper()
|
||||||
|
output += '#define LANGUAGE_PROGRESS_' + escaped_name + '_TRANSLATED ' + str(lang['data']['translationProgress']) + '\n'
|
||||||
|
output += '#define LANGUAGE_PROGRESS_' + escaped_name + '_APPROVED ' + str(lang['data']['approvalProgress']) + '\n\n'
|
||||||
with open("progress.h", 'w') as output_file:
|
with open("progress.h", 'w') as output_file:
|
||||||
output_file.write(output)
|
output_file.write(output)
|
||||||
|
|
Loading…
Reference in New Issue