name: Localization Check
on:
  push:
    branches: [develop]
    paths:
      - 'src/Resources/Locales/**'
  workflow_dispatch:
  workflow_call:

jobs:
  localization-check:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Set up Node.js
        uses: actions/setup-node@v6
        with:
          node-version: '24.x'

      - name: Install dependencies
        run: npm install fs-extra@11.2.0 path@0.12.7 xml2js@0.6.2

      - name: Run localization check
        run: node build/scripts/localization-check.js

      - name: Commit changes
        run: |
          git config --global user.name 'github-actions[bot]'
          git config --global user.email 'github-actions[bot]@users.noreply.github.com'
          if [ -n "$(git status --porcelain)" ]; then
            git add TRANSLATION.md src/Resources/Locales/*.axaml
            git commit -m 'doc: Update translation status and sort locale files'
            git push
          else
            echo "No changes to commit"
          fi
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
