From 2cbfb159d10ecf1fbf9abf2bfc9d60f0ca41dfd0 Mon Sep 17 00:00:00 2001 From: thewahome Date: Wed, 16 Oct 2024 09:49:21 +0300 Subject: [PATCH] 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