Auto-Translate UI keys and create PR #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PR-independent translations generation | |
on: | |
schedule: | |
- cron: "0 9 * * *" # Every day | |
workflow_dispatch: {} | |
jobs: | |
translations: | |
name: Translations | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v4 | |
name: Checkout | |
with: | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.x" | |
- name: Install Python dependencies | |
run: pip install gitpython openai | |
- name: Generate translations | |
run: python ui/src/translations/generate_translations.py | |
env: | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
- name: Set up Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20.x" | |
- name: Check keys matching | |
run: node ui/src/translations/check.js | |
- name: Set up Git | |
run: | | |
git config --global user.name "GitHub Action" | |
git config --global user.email "[email protected]" | |
- name: Check for changes and commit | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
BRANCH_NAME="chore/update-translations-$(date +%s)" | |
git checkout -b $BRANCH_NAME | |
git add ui/src/translations/*.json | |
if git diff --cached --quiet; then | |
echo "No changes to commit. Exiting with success." | |
exit 0 | |
fi | |
git commit -m "chore(translations): localize to languages other than English" | |
git push -u origin $BRANCH_NAME || (git push origin --delete $BRANCH_NAME && git push -u origin $BRANCH_NAME) | |
gh pr create --title "Translations from en.json" --body "This PR was created automatically by a GitHub Action." --base develop --head $BRANCH_NAME --assignee anna-geller --reviewer anna-geller |