Skip to content

Commit

Permalink
translation strings unique and parameterised
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome committed Oct 16, 2024
1 parent 2247d7a commit 2cbfb15
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions scripts/check-translations.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 { "<li>$_</li>" }
$results += [PSCustomObject]@{
Expand All @@ -32,18 +46,9 @@ $htmlTable = @"
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid black; padding: 8px; text-align: left; }
th { background-color: #f2f2f2; }
</style>
</head>
<body>
Expand All @@ -54,17 +59,14 @@ $htmlTable = @"
<th>Untranslated Strings</th>
</tr>
"@

foreach ($result in $results) {
$htmlTable += "<tr><td>$($result.LanguageFile) ($($result.Count))</td><td>$($result.UntranslatedStrings)</td></tr>"
}

$htmlTable += @"
</table>
</body>
</html>
"@

$htmlTable | Out-File -FilePath "untranslated_strings.html"

# Output a summary table to the workflow log
Expand Down

0 comments on commit 2cbfb15

Please sign in to comment.