Refactor translation handling across scripts

This commit is contained in:
Jeffrey
2026-10-21 19:45:58 +02:00
parent 97f3f805ef
commit 785f134153
12 changed files with 120 additions and 851 deletions
+71
View File
@@ -11,6 +11,7 @@ BeforeAll {
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
$script:LanguagesPath = Join-Path $PSScriptRoot '..\Config\Languages'
$featureConfig = Import-JsonFile -filePath (Join-Path $PSScriptRoot '..\Config\Features.json')
$appConfig = Import-JsonFile -filePath (Join-Path $PSScriptRoot '..\Config\Apps.json')
function Add-CatalogValues {
param($Catalog, [string]$Prefix, [hashtable]$Values)
@@ -32,6 +33,76 @@ BeforeAll {
ConvertFrom-Json -ErrorAction Stop
Add-CatalogValues -Catalog $content -Prefix $catalog -Values $baselineValues
}
function Assert-EnglishText {
param([string]$Key)
# Inspect the English catalog directly: translation fallback can hide missing keys.
$baselineValues.ContainsKey($Key) | Should -BeTrue -Because "en-US/$Key must exist"
$baselineValues[$Key] | Should -BeOfType ([string]) -Because "en-US/$Key must be text"
[string]::IsNullOrWhiteSpace($baselineValues[$Key]) |
Should -BeFalse -Because "en-US/$Key must not be blank"
}
}
Describe 'English catalog coverage for shipped definitions' {
It 'has a label and apply text for every feature, including CLI-only features' {
foreach ($feature in $featureConfig.Features) {
foreach ($field in 'Label', 'ApplyText') {
Assert-EnglishText -Key "Features.Features.$($feature.FeatureId).$field"
}
}
}
It 'has undo labels and apply text for every registry or custom undo operation' {
# These operations implement undo in Invoke-FeatureUndo without a RegistryUndoKey.
$customUndoIds = @('DisableStoreSearchSuggestions', 'EnableWindowsSandbox', 'EnableWindowsSubsystemForLinux')
foreach ($feature in $featureConfig.Features) {
if ($feature.RegistryUndoKey -or $feature.FeatureId -in $customUndoIds) {
foreach ($field in 'UndoLabel', 'ApplyUndoText') {
Assert-EnglishText -Key "Features.Features.$($feature.FeatureId).$field"
}
}
}
}
It 'has a tooltip for every feature displayed outside a UI group' {
$groupedFeatureIds = @($featureConfig.UiGroups | ForEach-Object {
$_.Values | ForEach-Object { $_.FeatureIds }
})
foreach ($feature in $featureConfig.Features) {
if ($feature.Category -and $feature.FeatureId -notin $groupedFeatureIds) {
Assert-EnglishText -Key "Features.Features.$($feature.FeatureId).ToolTip"
}
}
}
It 'has a label, tooltip, and every option label for each UI group' {
foreach ($group in $featureConfig.UiGroups) {
foreach ($field in 'Label', 'ToolTip') {
Assert-EnglishText -Key "Features.UiGroups.$($group.GroupId).$field"
}
foreach ($option in $group.Values) {
Assert-EnglishText -Key "Features.UiGroups.$($group.GroupId).Values.$($option.FeatureIds[0])"
}
}
}
It 'has a label for every feature category' {
foreach ($category in $featureConfig.Categories) {
Assert-EnglishText -Key "Categories.$($category.CategoryId).Label"
}
}
It 'has a friendly name and description for every app using its primary ID' {
foreach ($app in $appConfig.Apps) {
# Array entries are aliases of the first ID, as in Import-AppDetailsFromJson.
$primaryAppId = @($app.AppId)[0]
foreach ($field in 'FriendlyName', 'Description') {
Assert-EnglishText -Key "Apps.$primaryAppId.$field"
}
}
}
}
Describe 'Shipped language catalogs: <LanguageCode>' -ForEach $languageCases {