Auto Translate #86
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 | |
# Run this workflow every month on the first day of the month, or manually | |
# It will fetch the latest translations from Transifex, run the translation script, and open a PR. | |
# Once the PR is merged, the translations will be synced to Transifex. | |
on: | |
pull_request: | |
branches: | |
- main | |
paths: | |
- .github/workflows/auto-translate.yml | |
schedule: | |
- cron: "0 0 27,13 * *" | |
workflow_dispatch: | |
inputs: | |
limit: | |
description: "Character limit for translation" | |
required: false | |
default: 2000 | |
jobs: | |
auto-translate: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Python 3.11 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
- name: Install aiida-core-i18n | |
run: | | |
pip install -e .[dev] | |
- name: Install tx client | |
run: | | |
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash -s -- v1.6.9 | |
mv tx /usr/local/bin/tx | |
- name: Fetch latest PO files from Transifex | |
# -a: --all: Fetch all translation files | |
# -t: pull translations | |
# -f: regardless of timestamp | |
run: | | |
tx pull -a -t -f | |
env: | |
TX_TOKEN: ${{ secrets.TX_TOKEN }} | |
- name: Set characters limit base on event | |
id: set-limit | |
run: | | |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
echo "CHR_LIMIT=${{ github.event.inputs.limit }}" >> $GITHUB_OUTPUT | |
elif [ "${{ github.event_name }}" == "pull_request" ]; then | |
echo "CHR_LIMIT=200" >> $GITHUB_OUTPUT | |
else | |
# for cron job, check the api limit and run as many characters as possible (40% of the api limit, twice a month) | |
# otherwise use 80% of the api limit | |
CHR_LIMIT=$(aiida-core-i18n status -p avail | awk '{print int($1*0.4)}') | |
echo "Limiting to $CHR_LIMIT characters" | |
echo "CHR_LIMIT=$CHR_LIMIT" >> $GITHUB_OUTPUT | |
fi | |
env: | |
DEEPL_TOKEN: ${{ secrets.DEEPL_TOKEN }} | |
- name: Run translation script | |
run: | | |
python .github/scripts/translate.py --limit ${{ steps.set-limit.outputs.CHR_LIMIT }} translations/zh_CN/ | |
env: | |
DEEPL_TOKEN: ${{ secrets.DEEPL_TOKEN }} | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
commit-message: "Auto-translate PO files" | |
branch: auto-translate-${{ github.sha }} | |
title: "Auto-translate PO files" | |
body: "This PR includes the latest translations from bot script. It translates up to ${{ steps.set-limit.outputs.CHR_LIMIT }} characters." | |
reviewers: unkcpz | |
delete-branch: true | |
if: github.event_name != 'pull_request' |