name: "Crowdin Translations" run-name: "[๐ŸŒ]: Crowdin Translations #${{ github.run_number }}" on: push: branches: [dev] paths: - 'kubejs/assets/**/lang/en_us.json' - 'kubejs/assets/**/patchouli_books/**/en_us/**/*.json' workflow_dispatch: inputs: operation: description: 'Operation type' required: true default: 'both' type: choice options: - upload - download - both - status skip_pr: description: 'Skip pull request creation' required: false default: false type: boolean export_approved_only: description: 'Export only approved translations' required: false default: true type: boolean dry_run: description: 'Dry run mode (no actual changes)' required: false default: false type: boolean download_language: description: 'Download language (leave empty for all)' required: false default: '' type: choice options: - '' - 'de-DE' - 'es-ES' - 'fr-FR' - 'jp-JP' - 'pt-BR' - 'ru-RU' - 'uk-UA' - 'zh-CN' - 'zh-TW' schedule: # Run daily at 3 AM UTC - cron: '0 3 * * *' concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true permissions: contents: write pull-requests: write jobs: sync: runs-on: ubuntu-latest if: github.event.inputs.operation != 'status' || github.event.inputs.operation == '' steps: - name: Checkout repository uses: actions/checkout@v6 - name: Validate source files run: | echo " Validating source language files..." # Check for required English source files find kubejs/assets -name "en_us.json" -type f | while read file; do echo " Found source file: $file" # Basic JSON validation if ! jq empty "$file" 2>/dev/null; then echo " Invalid JSON in $file" exit 1 fi done echo " All source files are valid JSON" - name: Cache Crowdin source files uses: actions/cache@v5 with: path: ~/.crowdin/cache.json key: ${{ runner.os }}-crowdin-cache-${{ github.ref_name }}-${{ hashFiles('**/crowdin.yml') }} restore-keys: | ${{ runner.os }}-crowdin-cache-${{ github.ref_name }}- - name: Set localization branch name id: set_branch run: | if [ -z "${{ github.event.inputs.download_language }}" ]; then echo "branch_name=translations/all" >> $GITHUB_OUTPUT echo "pr_title_suffix=for ALL languages" >> $GITHUB_OUTPUT else lang=$(echo "${{ github.event.inputs.download_language }}" | tr '[:upper:]' '[:lower:]' | tr '-' '_') echo "branch_name=translations/$lang" >> $GITHUB_OUTPUT echo "pr_title_suffix=for ${{ github.event.inputs.download_language }} language" >> $GITHUB_OUTPUT fi - name: Create Pull Request uses: crowdin/github-action@v2.15.2 with: upload_sources: ${{ github.event.inputs.operation == 'upload' || github.event.inputs.operation == 'both' || github.event_name == 'schedule' }} upload_translations: false import_eq_suggestions: true skip_untranslated_files: true download_translations: ${{ github.event.inputs.operation == 'download' || github.event.inputs.operation == 'both' || github.event_name == 'schedule' }} download_language: ${{ github.event.inputs.download_language }} config: crowdin.yml localization_branch_name: ${{ steps.set_branch.outputs.branch_name }} create_pull_request: ${{ (github.event.inputs.skip_pr != 'true' || github.event.inputs.skip_pr == '') && ((github.event.inputs.operation == 'download' || github.event.inputs.operation == 'both') || github.event_name == 'schedule') }} export_only_approved: ${{ github.event.inputs.export_approved_only || github.event_name == 'schedule' }} commit_message: "[translation] New translations" dryrun_action: ${{ github.event.inputs.dry_run == 'true' || false }} pull_request_base_branch_name: 'dev' pull_request_team_reviewers: 'modern-team' pull_request_title: "[๐ŸŒ]: New Crowdin translations ${{ steps.set_branch.outputs.pr_title_suffix }}" pull_request_labels: "Pull request: Translation" pull_request_body: | ## ๐ŸŒ New translations from Crowdin ${{ steps.set_branch.outputs.pr_title_suffix }} ### ๐Ÿ“‹ Summary - **Trigger**: ${{ github.event_name }} - **Operation**: ${{ github.event.inputs.operation || 'auto-sync' }} - **Language**: ${{ github.event.inputs.download_language || 'All languages' }} - **Approved only**: ${{ github.event.inputs.export_approved_only || 'true' }} ### ๐Ÿ”„ Changes - Updated JSON translation files ${{ steps.set_branch.outputs.pr_title_suffix }} - Patchouli book translations - Language-specific improvements ### ๐Ÿงช Testing Please test the translations in-game: 1. Switch to different languages 2. Check mod descriptions and tooltips 3. Verify Patchouli guide content --- *Automated by [Crowdin GitHub Action](https://github.com/crowdin/github-action)* env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_TOKEN }} CROWDIN_ID: ${{ vars.CROWDIN_ID }} # Status check job status: runs-on: ubuntu-latest if: github.event.inputs.operation == 'status' || github.event.inputs.operation == '' steps: - name: Checkout repository uses: actions/checkout@v6 - name: Get Project Info id: project-info run: | # Get project name from Crowdin API PROJECT_INFO=$(curl -s -H "Authorization: Bearer ${{ secrets.CROWDIN_TOKEN }}" "https://api.crowdin.com/api/v2/projects/${{ vars.CROWDIN_ID }}") PROJECT_NAME=$(echo "$PROJECT_INFO" | jq -r '.data.name') echo "project-name=$PROJECT_NAME" >> $GITHUB_OUTPUT echo "Project name: $PROJECT_NAME" - name: Crowdin Translations Progress uses: crowdin/github-action@v2.15.2 with: command: 'status translation' config: crowdin.yml env: CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_TOKEN }} CROWDIN_ID: ${{ vars.CROWDIN_ID }} - name: Generate Status Report run: | echo "## ๐ŸŒ Crowdin Translation Status Report" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "**Project ID**: ${{ vars.CROWDIN_ID }}" >> $GITHUB_STEP_SUMMARY echo "**Project Name**: ${{ steps.project-info.outputs.project-name }}" >> $GITHUB_STEP_SUMMARY echo "**Language Filter**: ${{ github.event.inputs.download_language || 'All languages' }}" >> $GITHUB_STEP_SUMMARY echo "**Generated**: $(date -u)" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY # Get detailed language statistics using Crowdin CLI echo "### ๐Ÿ“Š Language Statistics" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY if [ -n "${{ github.event.inputs.download_language }}" ]; then echo "๐Ÿ” **Selected Language**: ${{ github.event.inputs.download_language }}" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY # Get status for specific language LANG_STATUS=$(crowdin status translation --language ${{ github.event.inputs.download_language }} --format json 2>/dev/null | jq -r '.languages[] | select(.code == "${{ github.event.inputs.download_language }}") | "\(.code): \(.progress.translated)% translated, \(.progress.approved)% approved"') if [ -n "$LANG_STATUS" ]; then echo "- **Progress**: $LANG_STATUS" >> $GITHUB_STEP_SUMMARY else echo "- **Status**: Language not found in project" >> $GITHUB_STEP_SUMMARY fi else echo "๐ŸŒ **All Languages Overview**" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY # Get overall project statistics crowdin status translation --format json 2>/dev/null | jq -r '.languages[] | "\(.code): \(.progress.translated)% translated, \(.progress.approved)% approved"' | while read line; do echo "$line" >> $GITHUB_STEP_SUMMARY done fi echo "" >> $GITHUB_STEP_SUMMARY echo "### ๐Ÿ“ˆ Overall Project Progress" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY # Get overall statistics OVERALL_STATS=$(crowdin status translation --format json 2>/dev/null | jq -r '"Overall: \(.progress.translated)% translated, \(.progress.approved)% approved, \(.progress.words.total) total words"') if [ -n "$OVERALL_STATS" ]; then echo "$OVERALL_STATS" >> $GITHUB_STEP_SUMMARY fi echo "" >> $GITHUB_STEP_SUMMARY echo "### ๐Ÿ“‹ Quick Actions" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "- ๐Ÿ”— [Crowdin Dashboard](https://crowdin.com/project/${{ steps.project-info.outputs.project-name }})" >> $GITHUB_STEP_SUMMARY echo "- ๐Ÿ“Š [Translation Management](https://crowdin.com/project/${{ steps.project-info.outputs.project-name }}/reports)" >> $GITHUB_STEP_SUMMARY echo "- ๐ŸŒ [Language Settings](https://crowdin.com/project/${{ steps.project-info.outputs.project-name }}/settings#languages)" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "๐Ÿ“Š Use detailed statistics above to review translation progress." >> $GITHUB_STEP_SUMMARY