🧰 (P) Update i18n source files #2
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: Sync Translation Target Files | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 0 * * *' | |
| jobs: | |
| sync-files: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout current repository | |
| uses: actions/checkout@v4 | |
| - name: Clone floorp repository | |
| run: | | |
| git clone https://github.com/Floorp-Projects/floorp-12.git floorp | |
| cd floorp | |
| git checkout main | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci -g | |
| - name: Read translation targets | |
| id: read-targets | |
| run: | | |
| TARGETS=$(node -e "const fs = require('fs'); const path = require('path'); const targets = JSON.parse(fs.readFileSync('src/apps/i18n-supports/translation-targets.json', 'utf8')); console.log(JSON.stringify(targets));") | |
| echo "targets=$TARGETS" >> $GITHUB_OUTPUT | |
| - name: Generate Crowdin.yml | |
| run: | | |
| TARGETS='${{ steps.read-targets.outputs.targets }}' | |
| echo "files:" > crowdin.yml | |
| echo "$TARGETS" | jq -c '.targets[]' | while read -r target; do | |
| SOURCE_PATH=$(echo "$target" | jq -r '.source_apth') | |
| SOURCE_FILE=$(echo "$TARGETS" | jq -r '.source_file') | |
| echo " - source: /$SOURCE_PATH/$SOURCE_FILE" >> crowdin.yml | |
| echo " translation: /$SOURCE_PATH/%locale%.json" >> crowdin.yml | |
| echo "" >> crowdin.yml | |
| done | |
| - name: Copy translation files | |
| run: | | |
| TARGETS='${{ steps.read-targets.outputs.targets }}' | |
| echo "$TARGETS" | jq -c '.targets[]' | while read -r target; do | |
| SOURCE_PATH=$(echo "$target" | jq -r '.source_apth') | |
| F18N_PATH=$(echo "$target" | jq -r '.f18n_path') | |
| SOURCE_FILE=$(echo "$TARGETS" | jq -r '.source_file') | |
| echo "Copying $SOURCE_FILE from $SOURCE_PATH to $F18N_PATH" | |
| mkdir -p "$F18N_PATH" | |
| cp "floorp/$SOURCE_PATH/$SOURCE_FILE" "$F18N_PATH" | |
| done | |
| - name: Commit and push changes | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git add . | |
| git commit -m "chore: sync translation target files and update crowdin.yml" || exit 0 | |
| git push |