Repository navigation
Pull Translations from Transifex #38
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: Pull Translations from Transifex | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| update-translation: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| version: [ '3.15' ] | |
| steps: | |
| - uses: styfle/cancel-workflow-action@main | |
| with: | |
| access_token: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: actions/setup-python@master | |
| with: | |
| python-version: 3 | |
| - name: Install Dependencies | |
| run: | | |
| sudo apt-get install -y gettext | |
| pip install requests cogapp polib transifex-python sphinx-intl blurb six | |
| curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash | |
| working-directory: /usr/local/bin | |
| - uses: actions/checkout@master | |
| with: | |
| ref: ${{ matrix.version }} | |
| fetch-depth: 0 | |
| - run: curl -O https://raw.githubusercontent.com/python-docs-translations/transifex-automations/master/sample-workflows/transifex-util.py | |
| - run: chmod +x transifex-util.py | |
| - run: ./transifex-util.py recreate_tx_config --language ta --project-slug python-newest --version ${{ matrix.version }} | |
| env: | |
| TX_TOKEN: ${{ secrets.TX_TOKEN }} | |
| - run: ./transifex-util.py fetch --language ta --project-slug python-newest --version ${{ matrix.version }} | |
| env: | |
| TX_TOKEN: ${{ secrets.TX_TOKEN }} | |
| - run: ./transifex-util.py delete_obsolete_files --language ta --project-slug python-newest --version ${{ matrix.version }} | |
| - name: Set up Git | |
| run: | | |
| git config --local user.email github-actions@github.com | |
| git config --local user.name "GitHub Action's update-translation job" | |
| # 1. SMART METRIC INSPECTION: Protect GitHub work from empty or degraded pulls | |
| - name: Protect GitHub translations from empty Transifex overwrites | |
| run: | | |
| git diff --name-only | grep '\.po$' | while read file; do | |
| if [ -f "$file" ]; then | |
| # Export the committed GitHub variant to a temporary path | |
| git show HEAD:"$file" > /tmp/github_version.po 2>/dev/null || echo "" > /tmp/github_version.po | |
| # Extract and isolate valid translated msgids using standard gettext tooling | |
| GITHUB_COUNT=$(msgattrib --translated /tmp/github_version.po 2>/dev/null | grep -c '^msgid' || echo 0) | |
| TRANSIFEX_COUNT=$(msgattrib --translated "$file" 2>/dev/null | grep -c '^msgid' || echo 0) | |
| echo "Inspecting $file -> GitHub translations count: $GITHUB_COUNT, Transifex count: $TRANSIFEX_COUNT" | |
| # If GitHub holds more verified strings, reject the incoming database change | |
| if [ "$GITHUB_COUNT" -gt "$TRANSIFEX_COUNT" ]; then | |
| echo "CRITICAL WARNING: Transifex payload is missing strings. Reverting file to GitHub baseline." | |
| git checkout HEAD -- "$file" | |
| fi | |
| fi | |
| done || true | |
| # 2. Filter files accurately based on what remains changed | |
| - name: Filter files | |
| run: | | |
| ! git diff -I'^"POT-Creation-Date: ' \ | |
| -I'^"Language-Team: ' \ | |
| -I'^# ' -I'^"Last-Translator: ' \ | |
| --exit-code \ | |
| && echo "SIGNIFICANT_CHANGES=1" >> $GITHUB_ENV || exit 0 | |
| - run: git add . ':!transifex-util.py' | |
| # 3. Safely commit only if there are valid changes remaining | |
| - run: git commit -m 'Update translation from Transifex' || echo "No changes to commit" | |
| if: ${{ env.SIGNIFICANT_CHANGES == '1' }} | |
| # 4. Push the safe updates back up to GitHub | |
| - uses: ad-m/github-push-action@master | |
| if: ${{ env.SIGNIFICANT_CHANGES == '1' }} | |
| with: | |
| branch: ${{ matrix.version }} | |
| github_token: ${{ secrets.GITHUB_TOKEN }} |