From 06ae700f11c56ebbc533f626b338f55bf4ed11d9 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 18 Apr 2021 20:09:35 +0200 Subject: [PATCH] Translations workflows --- .github/workflows/translations-download.yaml | 70 ++++++++++++++++++++ .github/workflows/translations-upload.yaml | 53 +++++++++++++++ .gitignore | 1 + 3 files changed, 124 insertions(+) create mode 100644 .github/workflows/translations-download.yaml create mode 100644 .github/workflows/translations-upload.yaml create mode 100644 .gitignore diff --git a/.github/workflows/translations-download.yaml b/.github/workflows/translations-download.yaml new file mode 100644 index 000000000..ba0854123 --- /dev/null +++ b/.github/workflows/translations-download.yaml @@ -0,0 +1,70 @@ +--- +name: Translations Download + +# yamllint disable-line rule:truthy +on: + schedule: + - cron: "0 8 * * *" + workflow_dispatch: + workflow_run: + workflows: ["Translations Upload"] + branches: [master] + types: + - completed + +jobs: + json: + name: JSON Lint + runs-on: ubuntu-latest + steps: + - name: โคต๏ธ Check out code from GitHub + uses: actions/checkout@v2.3.4 + with: + fetch-depth: 0 + - name: ๐Ÿ— Set up yq + uses: frenck/action-setup-yq@v1.0.0 + - name: ๐Ÿ— Set up the Lokalise CLI + uses: frenck/action-setup-lokalise@v1.0.0 + - name: โคต๏ธ Download translations + run: | + echo "Downloading translations to lokalise" + lokalise2 file download \ + --token "${LOKALISE_TOKEN}" \ + --project-id "${LOKALISE_PROJECT}" \ + --format yaml \ + --original-filenames=false \ + --export-empty-as base \ + --bundle-structure ".translations/%LANG_ISO%.yaml" + env: + LOKALISE_TOKEN: ${{ secrets.LOKALISE_TOKEN }} + LOKALISE_PROJECT: ${{ secrets.LOKALISE_PROJECT }} + - name: ๐Ÿš€ Process translations + run: | + addons=$(yq e '.addons | keys | .[]' .addons.yml) + mkdir -p .translations + for file in .translations/*.yaml; + do + filename=$(basename "${file}") + language="${filename%.*}" + echo "Processing downloaded translations in ${language}..." + while read addon; + do + if [[ -f "${addon}/translations/en.yaml" ]]; + then + echo "Processing downloaded translations in ${language} for ${addon}..." + yq e ".${addon}" "${file}" \ + > "${addon}/translations/${filename}" + fi + done <<<"${addons}" + done + - name: ๐Ÿš€ Commit changes + run: | + git config --local user.email "action@github.com" + git config --local user.name "${GITHUB_ACTOR}" + git add . + git commit -m "๐ŸŒ Updating translation" -a + - name: ๐Ÿš€ Push changes + uses: ad-m/github-push-action@v0.6 + with: + github_token: ${{ secrets.ACCESS_TOKEN }} + branch: ${{ github.ref }} diff --git a/.github/workflows/translations-upload.yaml b/.github/workflows/translations-upload.yaml new file mode 100644 index 000000000..37c201524 --- /dev/null +++ b/.github/workflows/translations-upload.yaml @@ -0,0 +1,53 @@ +--- +name: Translations Upload + +# yamllint disable-line rule:truthy +on: + workflow_dispatch: + workflow_run: + workflows: ["Repository Updater"] + branches: [master] + types: + - completed + +jobs: + upload: + name: Upload Translations + runs-on: ubuntu-latest + steps: + - name: โคต๏ธ Check out code from GitHub + uses: actions/checkout@v2.3.4 + - name: ๐Ÿ— Set up yq + uses: frenck/action-setup-yq@v1.0.0 + - name: ๐Ÿ— Set up the Lokalise CLI + uses: frenck/action-setup-lokalise@v1.0.0 + - name: ๐Ÿš€ Combine translations + run: | + addons=$(yq e '.addons | keys | .[]' .addons.yml) + mkdir -p .translations + while read addon; + do + if [[ -f "${addon}/translations/en.yaml" ]]; + then + echo "Prepping translation upload for $addon..." + ADDON="${addon}" \ + yq e '{env(ADDON): .}' "${addon}/translations/en.yaml" \ + > ".translations/${addon}.yaml" + fi + done <<<"${addons}" + + echo "Combining translation files..." + yq ea '. as $item ireduce ({}; . * $item)' ./.translations/*.yaml > translations.yaml + - name: ๐Ÿš€ Upload translations + run: | + echo "Uploading translations to lokalise" + lokalise2 file upload \ + --apply-tm \ + --lang-iso en \ + --poll \ + --token "${LOKALISE_TOKEN}" \ + --project-id "${LOKALISE_PROJECT}" \ + --file translations.yaml + env: + LOKALISE_TOKEN: ${{ secrets.LOKALISE_TOKEN }} + LOKALISE_PROJECT: ${{ secrets.LOKALISE_PROJECT }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..11437ae3e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.translations