diff --git a/.github/workflows/check-translations.yml b/.github/workflows/check-translations.yml new file mode 100644 index 0000000000..09b02848a1 --- /dev/null +++ b/.github/workflows/check-translations.yml @@ -0,0 +1,32 @@ +name: Check Translations + +on: + workflow_dispatch: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +jobs: + check-translations: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 22.x + + - name: Run translation check + run: ./scripts/check-translations.ps1 + shell: pwsh + + - name: Upload untranslated strings + uses: actions/upload-artifact@v4 + with: + name: untranslated-strings + path: ./untranslated_strings.html diff --git a/scripts/check-translations.ps1 b/scripts/check-translations.ps1 new file mode 100644 index 0000000000..c606ec9c61 --- /dev/null +++ b/scripts/check-translations.ps1 @@ -0,0 +1,83 @@ +# Step 1: Find all instances of vscode.l10n.t() and extract the strings from .ts and .tsx files +$withParamsPattern = 'vscode\.l10n\.t\(["''`](.+?)["''`],' +Get-ChildItem -Path vscode/microsoft-kiota/src -Recurse -Include *.ts, *.tsx | +Select-String -Pattern $withParamsPattern | +ForEach-Object { $_.Matches.Groups[1].Value } | +Sort-Object | +Get-Unique | +Out-File -FilePath "strings_with_params.txt" + +$withoutParamsPattern = 'vscode\.l10n\.t\(["' + "`'" + '`]([^"' + "`'" + '`]+)["' + "`'" + '`]\)' +Get-ChildItem -Path vscode/microsoft-kiota/src -Recurse -Include *.ts, *.tsx | +Select-String -Pattern $withoutParamsPattern | +ForEach-Object { $_.Matches.Groups[1].Value } | +Sort-Object | +Get-Unique | +Out-File -FilePath "strings_without_params.txt" + +Get-Content strings_with_params.txt, strings_without_params.txt | +Sort-Object | +Get-Unique | +Out-File -FilePath "strings.txt" + +# Step 2: Check translation files in the l10n folder +$results = @() +foreach ($file in Get-ChildItem -Path "vscode/microsoft-kiota/l10n" -Filter bundle.l10n.*.json -Recurse) { + $translations = Get-Content $file.FullName | + Select-String -Pattern '"[^"]+"' | + ForEach-Object { $_.Matches.Groups[0].Value.Trim('"') } | + Sort-Object + $missing = Compare-Object (Get-Content "strings.txt") $translations -PassThru | + Where-Object { $_.SideIndicator -eq "<=" } + + if ($missing) { + $untranslatedItems = $missing | ForEach-Object { "
  • $_
  • " } + $results += [PSCustomObject]@{ + "LanguageFile" = "$($file.Name)" + "Count" = "$($untranslatedItems.Count) found" + "UntranslatedStrings" = "" + } + } +} + +# Create the HTML table +$htmlTable = @" + + + + + + +

    Untranslated Strings

    + + + + + +"@ +foreach ($result in $results) { + $htmlTable += "" +} +$htmlTable += @" +
    Language FileUntranslated Strings
    $($result.LanguageFile) ($($result.Count))$($result.UntranslatedStrings)
    + + +"@ +$htmlTable | Out-File -FilePath "untranslated_strings.html" + +# Output a summary table to the workflow log +if ($results.Count -gt 0) { + Write-Host "Untranslated strings found. See untranslated_strings.html for details." -ForegroundColor Red + Write-Host "| Language File | Count |" + Write-Host "|----------------------------------------|---------|" + foreach ($result in $results) { + Write-Host "| $($result.LanguageFile) | $($result.Count) |" + } +} +else { + Write-Host "All strings have translations." -ForegroundColor Green +}