Skip to content

Transifex sync

Transifex sync #206

Workflow file for this run

name: Transifex sync
on:
workflow_dispatch:
schedule:
- cron: '0 9 * * 1'
permissions:
contents: write
pull-requests: write
jobs:
tx-sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup i18n-sync branch
run: |
# Fetch i18n-sync branch if it exists remotely
if git ls-remote --exit-code --heads origin i18n-sync; then
git fetch origin i18n-sync:i18n-sync
git checkout i18n-sync
else
# Create new branch from main
git checkout -b i18n-sync
fi
- name: Install Transifex client
run: |
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash
chmod +x ./tx
- name: Pull translations from Transifex
run: |
# Pull only translated strings, leaving untranslated ones empty
# This prevents replacing existing translations with English
# -f: force download, always use Transifex as source of truth (ignore timestamps)
# --mode onlytranslated: only includes translated strings, untranslated keys will be empty
# --minimum-perc 75: only pulls files that are at least 75% translated
# Empty strings will fallback to English at runtime via i18next
./tx --token "${{ secrets.TX_TOKEN }}" pull --all --force --mode onlytranslated --minimum-perc 75
- name: Commit and push changes
id: commit
run: |
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Add translation files
git add -A public/locales
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "::notice::No translation changes detected from Transifex"
{
echo "## πŸ“‹ Transifex Sync Summary"
echo ""
echo "βœ… **No changes detected**"
echo ""
echo "All translations are up to date."
} >> "$GITHUB_STEP_SUMMARY"
echo "changes=false" >> "$GITHUB_OUTPUT"
else
# Get statistics before committing
STATS=$(git diff --staged --stat)
FILES_CHANGED=$(git diff --staged --name-only)
FILES_COUNT=$(echo "$FILES_CHANGED" | wc -l)
# Commit changes
git commit --no-verify --signoff -m "chore: pull transifex translations"
SYNC_TIME=$(date -u +%Y-%m-%d\ %H:%M)
# Push to remote (force to handle any conflicts)
git push origin i18n-sync --force
# Create GitHub annotations
echo "::notice::Translation updates committed - $FILES_COUNT file(s) changed"
# Create job summary
{
echo "## πŸ“‹ Transifex Sync Summary"
echo ""
echo "βœ… **Translation updates found and committed**"
echo ""
echo "**Sync time:** $SYNC_TIME UTC"
echo "**Files changed:** $FILES_COUNT"
echo ""
echo "### πŸ“ Changed files:"
echo "\`\`\`"
echo "$FILES_CHANGED"
echo "\`\`\`"
echo ""
echo "### πŸ“Š Statistics:"
echo "\`\`\`diff"
echo "$STATS"
echo "\`\`\`"
} >> "$GITHUB_STEP_SUMMARY"
{
echo "changes=true"
echo "sync_time=$SYNC_TIME"
echo "files_count=$FILES_COUNT"
} >> "$GITHUB_OUTPUT"
fi
- name: Create pull request
if: steps.commit.outputs.changes == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Check if PR already exists
existing_pr=$(gh pr list --base main --head i18n-sync --state open --json number,url --jq '.[0]' || true)
if [ -n "$existing_pr" ]; then
PR_NUMBER=$(echo "$existing_pr" | jq -r '.number')
PR_URL=$(echo "$existing_pr" | jq -r '.url')
echo "::warning::Pull request #$PR_NUMBER already exists for i18n-sync branch"
# Update job summary with PR info
{
echo ""
echo "### πŸ”— Pull Request"
echo "⚠️ **Existing PR updated:** [#$PR_NUMBER]($PR_URL)"
} >> "$GITHUB_STEP_SUMMARY"
else
# Create new PR
body="Automated translation update from Transifex.
**Sync time:** ${{ steps.commit.outputs.sync_time }} UTC
**Files changed:** ${{ steps.commit.outputs.files_count }}
- Only pulls translated strings (empty strings fallback to English)
- Includes locales with 75%+ completion
To contribute translations: https://app.transifex.com/ipfs/ipfs-webui/"
PR_URL=$(gh pr create \
--base main \
--head i18n-sync \
--title "chore: pull new translations" \
--body "$body" \
--label "area/i18n/translations" || echo "")
if [ -n "$PR_URL" ]; then
echo "::notice::Pull request created: $PR_URL"
# Update job summary with PR info
{
echo ""
echo "### πŸ”— Pull Request"
echo "βœ… **New PR created:** $PR_URL"
} >> "$GITHUB_STEP_SUMMARY"
else
echo "::error::Failed to create pull request"
fi
fi