Skip to content

Crowdin CI Patch 2 #1738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 35 additions & 49 deletions .github/workflows/approve-translations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,45 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install Crowdin CLI
- name: Install dependencies
run: |
npm install -g @crowdin/cli@3
sudo apt-get install -y jq
npm i -g @crowdin/cli

- name: Approve top-voted translations for all languages
- name: Approve top-voted translations
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
[ -z "$CROWDIN_TOKEN" ] && echo "Missing token" && exit 1
[ -z "$CROWDIN_PROJECT_ID" ] && echo "Missing project id" && exit 1

echo "Start automatic approval crowdin translations..."

# Get all string IDs
STRING_IDS=$(curl -s -H "Authorization: Bearer $CROWDIN_TOKEN" \
"https://api.crowdin.com/api/v2/projects/$CROWDIN_PROJECT_ID/strings?limit=500" | jq -r '.data[].data.id')

# For each string, approve the translation with the most votes if not already approved
for STRING_ID in $STRING_IDS; do
TRANSLATIONS=$(curl -s -H "Authorization: Bearer $CROWDIN_TOKEN" \
"https://api.crowdin.com/api/v2/projects/$CROWDIN_PROJECT_ID/strings/$STRING_ID/translations?limit=100")

TOP=$(echo "$TRANSLATIONS" | jq -r '
.data
| map(select(.data.isApproved == false))
| max_by(.data.upvotesCount)
| select(.data.upvotesCount >= 0)
| .data.id')

if [ -n "$TOP" ]; then
curl -s -X POST -H "Authorization: Bearer $CROWDIN_TOKEN" \
-H "Content-Type: application/json" \
"https://api.crowdin.com/api/v2/projects/$CROWDIN_PROJECT_ID/translations/$STRING_ID/approvals" \
-d "{\"translationId\":$TOP}"
echo "Approved translation $TOP for string $STRING_ID"
fi
done

echo "Approval process finished."