Auto-Translate UI keys and create PR #34
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: Auto-Translate UI keys and create PR | |
on: | |
schedule: | |
- cron: "0 9-21 * * *" # Every hour from 9 AM to 9 PM | |
workflow_dispatch: | |
inputs: | |
retranslate_modified_keys: | |
description: "Whether to re-translate modified keys even if they already have translations." | |
type: choice | |
options: | |
- "false" | |
- "true" | |
default: "false" | |
required: false | |
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 ${{ github.event.inputs.retranslate_modified_keys }} | |
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: Commit and create PR | |
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 |