Skip to content

Commit

Permalink
Translations workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck committed Apr 18, 2021
1 parent 32311de commit 06ae700
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/translations-download.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
fetch-depth: 0
- name: 🏗 Set up yq
uses: frenck/[email protected]
- name: 🏗 Set up the Lokalise CLI
uses: frenck/[email protected]
- 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 "[email protected]"
git config --local user.name "${GITHUB_ACTOR}"
git add .
git commit -m "🌍 Updating translation" -a
- name: 🚀 Push changes
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.ACCESS_TOKEN }}
branch: ${{ github.ref }}
53 changes: 53 additions & 0 deletions .github/workflows/translations-upload.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- name: 🏗 Set up yq
uses: frenck/[email protected]
- name: 🏗 Set up the Lokalise CLI
uses: frenck/[email protected]
- 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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.translations

0 comments on commit 06ae700

Please sign in to comment.