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
+13
View File
@@ -63,6 +63,19 @@ Describe 'Get-RebootFeatureLabels' {
$result | Should -Contain 'Apply feature'
}
It 'resolves undo labels when feature metadata contains no display text' {
$script:Features = @{
ApplyFeature = [PSCustomObject]@{ RequiresReboot = $true }
UndoFeature = [PSCustomObject]@{ RequiresReboot = $true }
}
$result = @(Get-RebootFeatureLabels)
$result | Should -HaveCount 2
$result | Should -Contain 'Undo apply feature'
$result | Should -Contain 'Undo feature'
}
It 'falls back to the regular label when an undo selection has no undo label' {
$script:Params = @{}
$script:UndoParams = @{ ApplyFeature = $true }
+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 {
+1 -1
View File
@@ -151,7 +151,7 @@ Describe 'Language changes on existing controls' {
$disabled.ToolTip.Text | Should -Be (Get-Translation -Key 'TweaksAlreadyAppliedTooltip')
[object]::ReferenceEquals($group.SelectedItem, $selectedItem) | Should -BeTrue
$group.SelectedIndex | Should -Be 2
$selectedItem.Content | Should -Be (Get-GroupValueTranslation -GroupId 'SearchIcon' -FeatureId $script:UiControlMappings['Group_SearchIconCombo'].Values[1].FeatureIds[0] -FallbackLabel 'fallback')
$selectedItem.Content | Should -Be (Get-GroupValueTranslation -GroupId 'SearchIcon' -FeatureId $script:UiControlMappings['Group_SearchIconCombo'].Values[1].FeatureIds[0])
@(Get-PendingTweakActions -Window $window -ShowAppliedTweaksMode $true | ForEach-Object { "$($_.Action):$($_.FeatureId)" } | Sort-Object) | Should -Be $before
$script:FeatureLabelLookup['DisableTelemetry'] | Should -Be $checkbox.Content
foreach ($category in $script:CategoryLanguageControls) {
+8 -1
View File
@@ -7,6 +7,10 @@ BeforeAll {
function Wait-ForKeyPress {}
function Show-AppSelectionWindow { $false }
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
$script:Lang = Import-LanguageFile -LanguageCode 'en-US' -LanguagesPath (Join-Path $PSScriptRoot '..\Config\Languages')
. (Join-Path $PSScriptRoot '..\Scripts\CLI\Write-CliHeader.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\CLI\Write-PendingChanges.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\CLI\Show-CliAppRemoval.ps1')
@@ -20,7 +24,7 @@ Describe 'Show-CliMenuOptions' {
BeforeEach {
$script:Params = @{}
$script:ControlParams = @('WhatIf', 'Silent')
$script:Features = @{ DisableTelemetry = [PSCustomObject]@{ Label = 'Disable telemetry' }; CreateRestorePoint = [PSCustomObject]@{ Label = 'Create restore point' } }
$script:Features = @{ DisableTelemetry = [PSCustomObject]@{ FeatureId = 'DisableTelemetry' }; CreateRestorePoint = [PSCustomObject]@{ FeatureId = 'CreateRestorePoint' } }
$script:SelectedApps = @('One.App', 'Two.App')
$script:SavedSettingsFilePath = 'C:\Settings\LastUsedSettings.json'
$script:DefaultSettingsFilePath = 'C:\Settings\DefaultSettings.json'
@@ -62,6 +66,9 @@ Describe 'Show-CliMenuOptions' {
Should -Invoke Generate-AppsList -Times 1 -Exactly
Should -Invoke Read-Host -Times 1 -Exactly
Should -Invoke Write-Output -Times 2 -ParameterFilter { $InputObject -like '- *' }
Should -Invoke Write-Output -Times 1 -Exactly -ParameterFilter {
$InputObject -eq "- $(Get-Translation -Key 'DisableTelemetry' -Field 'Label' -Section 'Features')"
}
}
It 'returns the saved-settings menu option only when the file is available' {