4.0.0-beta.3 #7
Workflow file for this run
This file contains hidden or 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 Approve Crowdin Translations | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| jobs: | |
| approve-translations: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| - name: Install Crowdin CLI | |
| run: | | |
| npm install -g @crowdin/cli@3 | |
| - name: Approve top-voted translations for all languages | |
| env: | |
| CROWDIN_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} | |
| CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} | |
| run: | | |
| set -e | |
| if [ -z "$CROWDIN_TOKEN" ] || [ -z "$CROWDIN_PROJECT_ID" ]; then | |
| echo "Crowdin token or project id is missing!" | |
| exit 1 | |
| fi | |
| echo "Start automatic approval Crowdin Translation..." | |
| language_ids=$(crowdin api list-languages --project-id=$CROWDIN_PROJECT_ID --plain | jq -r '.data[].data.id' || true) | |
| if [ -z "$language_ids" ]; then | |
| echo "No language ids found, check Crowdin project or CLI output." | |
| exit 1 | |
| fi | |
| string_ids=$(crowdin api list-strings --project-id=$CROWDIN_PROJECT_ID --plain | jq -r '.data[].data.id' || true) | |
| if [ -z "$string_ids" ]; then | |
| echo "No string ids found, check Crowdin project or CLI output." | |
| exit 1 | |
| fi | |
| for lang in $language_ids; do | |
| echo "Processing language $lang" | |
| translations=$(crowdin api list-string-translations --project-id=$CROWDIN_PROJECT_ID --language-id=$lang --plain) | |
| for sid in $string_ids; do | |
| best=$(echo "$translations" | jq -r " | |
| .data[] | |
| | .data | |
| | select(.stringId == \"$sid\" and .votes > 0) | |
| | {\"id\": .id, \"votes\": .votes} | |
| " | jq -s 'sort_by(-.votes) | .[0] | .id') | |
| if [ -n "$best" ] && [ "$best" != "null" ]; then | |
| echo " → Approved translation $best for string $sid" | |
| crowdin api edit-translation \ | |
| --project-id=$CROWDIN_PROJECT_ID \ | |
| --translation-id=$best \ | |
| --approved=true | |
| fi | |
| done | |
| done |