diff --git a/.github/workflows/crowdin-daily.yml b/.github/workflows/crowdin-daily.yml new file mode 100644 index 0000000000..2b69e8773d --- /dev/null +++ b/.github/workflows/crowdin-daily.yml @@ -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 diff --git a/intl/crowdin.yaml b/intl/crowdin.yaml index e6f926afc6..010f5f1450 100644 --- a/intl/crowdin.yaml +++ b/intl/crowdin.yaml @@ -1,5 +1,6 @@ -"project_identifier": "retroarch" -"api_key": "_secret_" +"project_id": "380544" +"api_token": "_secret_" +"base_url": "https://api.crowdin.com" "preserve_hierarchy": true "files": diff --git a/intl/crowdin_sync.py b/intl/crowdin_sync.py index 7896281d2e..60f618dce1 100755 --- a/intl/crowdin_sync.py +++ b/intl/crowdin_sync.py @@ -32,7 +32,7 @@ jar_name = 'crowdin-cli.jar' if not os.path.isfile(jar_name): print('download crowdin-cli.jar') 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) with zipfile.ZipFile(crowdin_cli_file, 'r') as zip_ref: jar_dir = zip_ref.namelist()[0] @@ -56,7 +56,7 @@ print('wait for crowdin server to process data') time.sleep(10) 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') for file in os.listdir(dir_path): diff --git a/intl/fetch_progress.py b/intl/fetch_progress.py index ae7bdbce4d..d9656769ab 100755 --- a/intl/fetch_progress.py +++ b/intl/fetch_progress.py @@ -6,12 +6,20 @@ import yaml with open("crowdin.yaml", 'r') as 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 = '' - for lang in r.json(): - output += '/* ' + lang['name'] + ' */\n' - escaped_name = lang['name'].replace(', ', '_').replace(' ', '_').upper() - output += '#define LANGUAGE_PROGRESS_' + escaped_name + '_TRANSLATED ' + str(lang['translated_progress']) + '\n' - output += '#define LANGUAGE_PROGRESS_' + escaped_name + '_APPROVED ' + str(lang['approved_progress']) + '\n\n' + for lang in res1.json()['data']: + lang_id = lang['data']['languageId'] + url2 = 'https://api.crowdin.com/api/v2/languages/' + lang_id + res2 = requests.get(url2, headers=headers) + 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: output_file.write(output)