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
+3 -4
View File
@@ -6,8 +6,7 @@
Iterates over every non-control parameter in $script:Params and emits a
human-readable line for each change that will be applied. For the
'RemoveApps' parameter the list of targeted app names is displayed
inline. Feature labels are resolved from Features.json when available;
otherwise the raw parameter name is used as a fallback.
inline. Feature labels are resolved from the language catalogs.
After printing the summary the function pauses until the user presses
Enter, giving them an opportunity to review and cancel via Ctrl+C.
@@ -16,7 +15,7 @@ function Write-PendingChanges {
Write-Output "Win11Debloat will make the following changes:"
if ($script:Params['CreateRestorePoint']) {
Write-Output "- $($script:Features['CreateRestorePoint'].Label)"
Write-Output "- $(Get-Translation -Key 'CreateRestorePoint' -Field 'Label' -Section 'Features')"
}
foreach ($parameterName in $script:Params.Keys) {
if ($script:ControlParams -contains $parameterName) {
@@ -45,7 +44,7 @@ function Write-PendingChanges {
continue
}
default {
$message = $script:Features[$parameterName].Label
$message = Get-Translation -Key $parameterName -Field 'Label' -Section 'Features'
Write-Output "- $message"
continue
}
+3 -5
View File
@@ -20,7 +20,7 @@ function Invoke-FeatureApply {
try {
# Resolve feature metadata from Features.json
$feature = $script:Features[$FeatureId]
$applyText = $feature.ApplyText
$applyText = Get-Translation -Key $FeatureId -Field 'ApplyText' -Section 'Features'
# ---- Registry-backed features: import .reg file, then handle additional tasks ----
if ($feature.RegistryKey) {
@@ -162,7 +162,7 @@ function Invoke-FeatureUndo {
return $false
}
$undoText = if ($feature.ApplyUndoText) { $feature.ApplyUndoText } elseif ($feature.UndoLabel) { $feature.UndoLabel } else { $FeatureId }
$undoText = Get-Translation -Key $FeatureId -Field 'ApplyUndoText' -Section 'Features'
try {
# ---- Registry-backed features: import undo data, then handle additional tasks ----
@@ -308,9 +308,7 @@ function Invoke-UndoFeatures {
foreach ($featureId in $FeatureIds) {
if ($script:CancelRequested) { return }
$f = if ($script:Features.ContainsKey($featureId)) { $script:Features[$featureId] } else { $null }
$undoLabel = if ($f -and $f.UndoLabel) { Get-Translation -Key $featureId -Field 'UndoLabel' -Section 'Features' } else { $featureId }
$undoText = if ($f -and $f.ApplyUndoText) { Get-Translation -Key $featureId -Field 'ApplyUndoText' -Section 'Features' } else { $undoLabel }
$undoText = Get-Translation -Key $featureId -Field 'ApplyUndoText' -Section 'Features'
if ($script:ApplyProgressCallback) {
& $script:ApplyProgressCallback $step $TotalSteps $undoText
+3 -5
View File
@@ -291,7 +291,7 @@ function Get-Translation {
<#
.SYNOPSIS
Looks up a translated label for one value of a UiGroup, falling back to en-US, then to the raw label.
Looks up a translated label for one value of a UiGroup, falling back to en-US, then to the feature ID.
.DESCRIPTION
UiGroups[GroupId].Values in the language files is a FeatureId -> Label map, one level deeper
@@ -304,13 +304,11 @@ function Get-GroupValueTranslation {
[string]$GroupId,
[Parameter(Mandatory)]
[string]$FeatureId,
[Parameter(Mandatory)]
[string]$FallbackLabel,
[object]$Lang = $script:Lang
)
if (-not $Lang) {
return $FallbackLabel
return $FeatureId
}
foreach ($candidateLang in (Get-LanguageFallbackChain -Lang $Lang)) {
@@ -325,7 +323,7 @@ function Get-GroupValueTranslation {
}
}
return $FallbackLabel
return $FeatureId
}
<#
+7 -6
View File
@@ -11,7 +11,7 @@
.PARAMETER Mapping
A control mapping with Type and either FeatureId or GroupId and Values. Group values
contain FeatureIds and fallback Label text.
contain FeatureIds.
.PARAMETER Features
The feature definitions keyed by FeatureId. Defaults to $script:Features.
@@ -30,7 +30,7 @@ function Get-TweakControlText {
$label = Get-Translation -Key $Mapping.GroupId -Field 'Label' -Section 'UiGroups'
$tooltip = Get-Translation -Key $Mapping.GroupId -Field 'ToolTip' -Section 'UiGroups'
$options += @($Mapping.Values | ForEach-Object {
Get-GroupValueTranslation -GroupId $Mapping.GroupId -FeatureId $_.FeatureIds[0] -FallbackLabel $_.Label
Get-GroupValueTranslation -GroupId $Mapping.GroupId -FeatureId $_.FeatureIds[0]
})
}
else {
@@ -66,8 +66,9 @@ function Update-FeatureLabelLookup {
$script:UndoFeatureLabelLookup = @{}
foreach ($feature in $Features) {
$script:FeatureLabelLookup[$feature.FeatureId] = Get-Translation -Key $feature.FeatureId -Field 'Label' -Section 'Features'
if ($feature.UndoLabel) {
$script:UndoFeatureLabelLookup[$feature.FeatureId] = Get-Translation -Key $feature.FeatureId -Field 'UndoLabel' -Section 'Features'
$undoLabel = Get-Translation -Key $feature.FeatureId -Field 'UndoLabel' -Section 'Features'
if ($undoLabel -ne $feature.FeatureId) {
$script:UndoFeatureLabelLookup[$feature.FeatureId] = $undoLabel
}
}
}
@@ -244,7 +245,7 @@ function New-DynamicTweakControls {
$text = Get-TweakControlText -Mapping $mapping -Features $featureMap
$controlName = ("Feature_{0}_Combo" -f $feature.FeatureId) -replace '[^a-zA-Z0-9_]', ''
$control = New-LabeledCombo -parent $parent -labelText $text.Label -comboName $controlName -items $text.Options
if ($feature.ToolTip -or $feature.DisableWhenApplied -eq $true) {
if ($text.ToolTip -and $text.ToolTip -ne $feature.FeatureId) {
Set-TweakControlToolTip -control $control -tooltipText $text.ToolTip -ShowOnDisabled
}
$script:UiControlMappings[$controlName] = $mapping
@@ -482,7 +483,7 @@ function New-DynamicTweakControls {
$comboName = 'Group_{0}Combo' -f $group.GroupId
if (-not $panel) { $panel = Get-OrCreateCategoryCard -categoryObj $categoryObj }
$combo = New-LabeledCombo -parent $panel -labelText $text.Label -comboName $comboName -items $text.Options
if ($group.ToolTip) {
if ($text.ToolTip -and $text.ToolTip -ne $group.GroupId) {
Set-TweakControlToolTip -control $combo -tooltipText $text.ToolTip
}
$script:UiControlMappings[$comboName] = $mapping
+3 -3
View File
@@ -13,9 +13,9 @@ function Get-RebootFeatureLabels {
foreach ($paramKey in $candidateParamKeys) {
if ($script:Features.ContainsKey($paramKey) -and $script:Features[$paramKey].RequiresReboot -eq $true) {
$feature = $script:Features[$paramKey]
$isUndo = $script:UndoParams.ContainsKey($paramKey)
$displayLabel = if ($isUndo -and $feature.UndoLabel) { Get-Translation -Key $paramKey -Field 'UndoLabel' -Section 'Features' } else { Get-Translation -Key $paramKey -Field 'Label' -Section 'Features' }
$undoLabel = Get-Translation -Key $paramKey -Field 'UndoLabel' -Section 'Features'
$displayLabel = if ($isUndo -and $undoLabel -ne $paramKey) { $undoLabel } else { Get-Translation -Key $paramKey -Field 'Label' -Section 'Features' }
if (-not [string]::IsNullOrWhiteSpace([string]$displayLabel)) {
[void]$rebootFeatureLabels.Add([string]$displayLabel)
@@ -24,4 +24,4 @@ function Get-RebootFeatureLabels {
}
return $rebootFeatureLabels
}
}