From 128b3787db8a1a15bcba57389ca81eb161579152 Mon Sep 17 00:00:00 2001 From: thewahome Date: Tue, 15 Oct 2024 13:14:18 +0300 Subject: [PATCH 01/10] Check for missing translations --- .github/workflows/check-translations.yml | 34 +++++++++++ scripts/check-translations.ps1 | 75 ++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 .github/workflows/check-translations.yml create mode 100644 scripts/check-translations.ps1 diff --git a/.github/workflows/check-translations.yml b/.github/workflows/check-translations.yml new file mode 100644 index 0000000000..b9bec792b5 --- /dev/null +++ b/.github/workflows/check-translations.yml @@ -0,0 +1,34 @@ +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: 18.x + + - name: Run translation check + working-directory: vscode/microsoft-kiota + run: scripts/check-translations.ps1 + shell: pwsh + + - name: Upload untranslated strings + if: failure() + uses: actions/upload-artifact@v2 + with: + name: untranslated-strings + path: vscode/microsoft-kiota/untranslated_strings.html diff --git a/scripts/check-translations.ps1 b/scripts/check-translations.ps1 new file mode 100644 index 0000000000..d785eff13f --- /dev/null +++ b/scripts/check-translations.ps1 @@ -0,0 +1,75 @@ +# Step 1: Find all instances of vscode.l10n.t() and extract the strings from .ts and .tsx files +Get-ChildItem -Path src -Recurse -Include *.ts, *.tsx | +Select-String -Pattern 'vscode.l10n.t\("([^"]+)"\)' | +ForEach-Object { $_.Matches.Groups[1].Value } | +Sort-Object | +Out-File -FilePath "strings.txt" + +# Step 2: Check translation files in the l10n folder +$results = @() +foreach ($file in Get-ChildItem -Path "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) ($($untranslatedItems.Count) found)" + "UntranslatedStrings" = "" + } + } +} + +# Create the HTML table +$htmlTable = @" + + + + + + +

    Untranslated Strings

    + + + + + +"@ + +foreach ($result in $results) { + $htmlTable += "" +} + +$htmlTable += @" +
    Language FileUntranslated Strings
    $($result.LanguageFile)$($result.UntranslatedStrings)
    + + +"@ + +$htmlTable | Out-File -FilePath "untranslated_strings.html" + +if ($results.Count -gt 0) { + Write-Host "Untranslated strings found. See untranslated_strings.html for details." -ForegroundColor Red + exit 1 +} +else { + Write-Host "All strings have translations." -ForegroundColor Green +} From 91c669ced32ade421dcf03abbab22b15de540f9e Mon Sep 17 00:00:00 2001 From: thewahome Date: Tue, 15 Oct 2024 13:24:13 +0300 Subject: [PATCH 02/10] upgrade upload artifacts version --- .github/workflows/check-translations.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-translations.yml b/.github/workflows/check-translations.yml index b9bec792b5..6d2c69d243 100644 --- a/.github/workflows/check-translations.yml +++ b/.github/workflows/check-translations.yml @@ -28,7 +28,7 @@ jobs: - name: Upload untranslated strings if: failure() - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: untranslated-strings path: vscode/microsoft-kiota/untranslated_strings.html From ef47c9a34166e8b1c20056945e8015904ab6b7c5 Mon Sep 17 00:00:00 2001 From: thewahome Date: Tue, 15 Oct 2024 13:27:16 +0300 Subject: [PATCH 03/10] Fix translation check script path in check-translations.yml --- .github/workflows/check-translations.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-translations.yml b/.github/workflows/check-translations.yml index 6d2c69d243..df3b5aa024 100644 --- a/.github/workflows/check-translations.yml +++ b/.github/workflows/check-translations.yml @@ -20,10 +20,11 @@ jobs: uses: actions/setup-node@v4 with: node-version: 18.x + - name: Run translation check working-directory: vscode/microsoft-kiota - run: scripts/check-translations.ps1 + run: ./scripts/check-translations.ps1 shell: pwsh - name: Upload untranslated strings From 03dde6ebe112a9b9bd0972c5ab91e2008b9dc937 Mon Sep 17 00:00:00 2001 From: thewahome Date: Tue, 15 Oct 2024 13:37:29 +0300 Subject: [PATCH 04/10] change working directories --- .github/workflows/check-translations.yml | 2 -- scripts/check-translations.ps1 | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/check-translations.yml b/.github/workflows/check-translations.yml index df3b5aa024..adf436535d 100644 --- a/.github/workflows/check-translations.yml +++ b/.github/workflows/check-translations.yml @@ -21,9 +21,7 @@ jobs: with: node-version: 18.x - - name: Run translation check - working-directory: vscode/microsoft-kiota run: ./scripts/check-translations.ps1 shell: pwsh diff --git a/scripts/check-translations.ps1 b/scripts/check-translations.ps1 index d785eff13f..600ee2a86d 100644 --- a/scripts/check-translations.ps1 +++ b/scripts/check-translations.ps1 @@ -1,5 +1,5 @@ # Step 1: Find all instances of vscode.l10n.t() and extract the strings from .ts and .tsx files -Get-ChildItem -Path src -Recurse -Include *.ts, *.tsx | +Get-ChildItem -Path vscode/microsoft-kiota/src -Recurse -Include *.ts, *.tsx | Select-String -Pattern 'vscode.l10n.t\("([^"]+)"\)' | ForEach-Object { $_.Matches.Groups[1].Value } | Sort-Object | From c67f86b0e9915c7c10987ae5c9a89ffa5752c15a Mon Sep 17 00:00:00 2001 From: thewahome Date: Tue, 15 Oct 2024 13:51:29 +0300 Subject: [PATCH 05/10] correct where items are checked --- .github/workflows/check-translations.yml | 5 ++--- scripts/check-translations.ps1 | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-translations.yml b/.github/workflows/check-translations.yml index adf436535d..1515e522ea 100644 --- a/.github/workflows/check-translations.yml +++ b/.github/workflows/check-translations.yml @@ -20,14 +20,13 @@ jobs: uses: actions/setup-node@v4 with: node-version: 18.x - + - name: Run translation check run: ./scripts/check-translations.ps1 shell: pwsh - name: Upload untranslated strings - if: failure() uses: actions/upload-artifact@v4 with: name: untranslated-strings - path: vscode/microsoft-kiota/untranslated_strings.html + path: ./untranslated_strings.html diff --git a/scripts/check-translations.ps1 b/scripts/check-translations.ps1 index 600ee2a86d..8798d9a428 100644 --- a/scripts/check-translations.ps1 +++ b/scripts/check-translations.ps1 @@ -7,7 +7,7 @@ Out-File -FilePath "strings.txt" # Step 2: Check translation files in the l10n folder $results = @() -foreach ($file in Get-ChildItem -Path "l10n" -Filter bundle.l10n.*.json -Recurse) { +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('"') } | From 7eee5b5845a0c4ec5e0c58098e7bc0e39a499504 Mon Sep 17 00:00:00 2001 From: thewahome Date: Tue, 15 Oct 2024 14:03:45 +0300 Subject: [PATCH 06/10] No exit with errror --- scripts/check-translations.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/check-translations.ps1 b/scripts/check-translations.ps1 index 8798d9a428..2e07a93b1b 100644 --- a/scripts/check-translations.ps1 +++ b/scripts/check-translations.ps1 @@ -68,7 +68,6 @@ $htmlTable | Out-File -FilePath "untranslated_strings.html" if ($results.Count -gt 0) { Write-Host "Untranslated strings found. See untranslated_strings.html for details." -ForegroundColor Red - exit 1 } else { Write-Host "All strings have translations." -ForegroundColor Green From c3e6f4460121cddedeba710c14bdb2c371831dd5 Mon Sep 17 00:00:00 2001 From: thewahome Date: Tue, 15 Oct 2024 14:11:24 +0300 Subject: [PATCH 07/10] provide summary --- scripts/check-translations.ps1 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/check-translations.ps1 b/scripts/check-translations.ps1 index 2e07a93b1b..8d4821925d 100644 --- a/scripts/check-translations.ps1 +++ b/scripts/check-translations.ps1 @@ -19,7 +19,8 @@ foreach ($file in Get-ChildItem -Path "vscode/microsoft-kiota/l10n" -Filter bund if ($missing) { $untranslatedItems = $missing | ForEach-Object { "
  • $_
  • " } $results += [PSCustomObject]@{ - "LanguageFile" = "$($file.Name) ($($untranslatedItems.Count) found)" + "LanguageFile" = "$($file.Name)" + "Count" = "$($untranslatedItems.Count) found" "UntranslatedStrings" = "
      $($untranslatedItems -join "`n")
    " } } @@ -55,7 +56,7 @@ $htmlTable = @" "@ foreach ($result in $results) { - $htmlTable += "$($result.LanguageFile)$($result.UntranslatedStrings)" + $htmlTable += "$($result.LanguageFile) ($($result.Count))$($result.UntranslatedStrings)" } $htmlTable += @" @@ -66,8 +67,14 @@ $htmlTable += @" $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 From 2247d7a23fd5de1ac470c2d7a4fb243daf54c25e Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 15 Oct 2024 09:23:16 -0400 Subject: [PATCH 08/10] Update .github/workflows/check-translations.yml --- .github/workflows/check-translations.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-translations.yml b/.github/workflows/check-translations.yml index 1515e522ea..09b02848a1 100644 --- a/.github/workflows/check-translations.yml +++ b/.github/workflows/check-translations.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v4 with: - node-version: 18.x + node-version: 22.x - name: Run translation check run: ./scripts/check-translations.ps1 From 2cbfb159d10ecf1fbf9abf2bfc9d60f0ca41dfd0 Mon Sep 17 00:00:00 2001 From: thewahome Date: Wed, 16 Oct 2024 09:49:21 +0300 Subject: [PATCH 09/10] translation strings unique and parameterised --- scripts/check-translations.ps1 | 46 ++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/scripts/check-translations.ps1 b/scripts/check-translations.ps1 index 8d4821925d..86a70da5a5 100644 --- a/scripts/check-translations.ps1 +++ b/scripts/check-translations.ps1 @@ -1,8 +1,23 @@ # Step 1: Find all instances of vscode.l10n.t() and extract the strings from .ts and .tsx files -Get-ChildItem -Path vscode/microsoft-kiota/src -Recurse -Include *.ts, *.tsx | -Select-String -Pattern 'vscode.l10n.t\("([^"]+)"\)' | -ForEach-Object { $_.Matches.Groups[1].Value } | -Sort-Object | +$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 @@ -12,10 +27,9 @@ foreach ($file in Get-ChildItem -Path "vscode/microsoft-kiota/l10n" -Filter bund Select-String -Pattern '"[^"]+"' | ForEach-Object { $_.Matches.Groups[0].Value.Trim('"') } | Sort-Object - - $missing = Compare-Object (Get-Content "strings.txt") $translations -PassThru | + $missing = Compare-Object (Get-Content "strings.txt") $translations -PassThru | Where-Object { $_.SideIndicator -eq "<=" } - + if ($missing) { $untranslatedItems = $missing | ForEach-Object { "
  • $_
  • " } $results += [PSCustomObject]@{ @@ -32,18 +46,9 @@ $htmlTable = @" @@ -54,17 +59,14 @@ $htmlTable = @" Untranslated Strings "@ - foreach ($result in $results) { $htmlTable += "$($result.LanguageFile) ($($result.Count))$($result.UntranslatedStrings)" } - $htmlTable += @" "@ - $htmlTable | Out-File -FilePath "untranslated_strings.html" # Output a summary table to the workflow log From 75b5411edbe74090bd2ba5378c3297db99fcc4bd Mon Sep 17 00:00:00 2001 From: Charles Wahome Date: Tue, 22 Oct 2024 15:13:19 +0300 Subject: [PATCH 10/10] make regex into a continuous string Co-authored-by: Caleb Kiage <747955+calebkiage@users.noreply.github.com> --- scripts/check-translations.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check-translations.ps1 b/scripts/check-translations.ps1 index 86a70da5a5..c606ec9c61 100644 --- a/scripts/check-translations.ps1 +++ b/scripts/check-translations.ps1 @@ -1,5 +1,5 @@ # Step 1: Find all instances of vscode.l10n.t() and extract the strings from .ts and .tsx files -$withParamsPattern = 'vscode\.l10n\.t\(["' + "`'" + '`](.+?)["' + "`'" + '`],' +$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 } |