mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-11-25 23:16:15 +01:00
Refactor feature label handling to utilize language catalogs (#890)
This commit is contained in:
@@ -6,7 +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;
|
||||
inline. Feature labels are resolved from the language catalogs when available;
|
||||
otherwise the raw parameter name is used as a fallback.
|
||||
|
||||
After printing the summary the function pauses until the user presses
|
||||
@@ -16,7 +16,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 +45,7 @@ function Write-PendingChanges {
|
||||
continue
|
||||
}
|
||||
default {
|
||||
$message = $script:Features[$parameterName].Label
|
||||
$message = Get-Translation -Key $parameterName -Field 'Label' -Section 'Features'
|
||||
Write-Output "- $message"
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -323,7 +323,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
|
||||
@@ -336,13 +336,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)) {
|
||||
@@ -357,7 +355,7 @@ function Get-GroupValueTranslation {
|
||||
}
|
||||
}
|
||||
|
||||
return $FallbackLabel
|
||||
return $FeatureId
|
||||
}
|
||||
|
||||
<#
|
||||
|
||||
@@ -1,18 +1,6 @@
|
||||
# MainWindow-Deployment.ps1
|
||||
# Overview generation, pending tweak actions, feature labels, tweak preset maps, apply logic, user mode state, user selection, and validation.
|
||||
|
||||
function Get-UndoFeatureLabel {
|
||||
param([string]$FeatureId)
|
||||
|
||||
$undoLabel = $script:UndoFeatureLabelLookup[$FeatureId]
|
||||
if (-not [string]::IsNullOrWhiteSpace([string]$undoLabel)) {
|
||||
return [string]$undoLabel
|
||||
}
|
||||
|
||||
# Fall back to the regular label (prefixed for undo context)
|
||||
return [string]$script:FeatureLabelLookup[$FeatureId]
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Returns the tweak actions that are pending based on the current UI state.
|
||||
@@ -61,7 +49,7 @@ function Get-PendingTweakActions {
|
||||
$actions.Add([PSCustomObject]@{
|
||||
Action = 'Undo'
|
||||
FeatureId = [string]$mapping.FeatureId
|
||||
Label = [string](Get-UndoFeatureLabel -FeatureId $mapping.FeatureId)
|
||||
Label = [string]$script:UndoFeatureLabelLookup[$mapping.FeatureId]
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -129,12 +117,7 @@ function New-Overview {
|
||||
}
|
||||
|
||||
foreach ($tweakAction in @(Get-PendingTweakActions -Window $Window -ShowAppliedTweaksMode:$showAppliedTweaksMode)) {
|
||||
if ($tweakAction.Action -eq 'Undo') {
|
||||
$changesList += Get-Translation -Key 'DeployChangeUndoPrefix' -FormatArgs @($tweakAction.Label)
|
||||
}
|
||||
else {
|
||||
$changesList += $tweakAction.Label
|
||||
}
|
||||
$changesList += $tweakAction.Label
|
||||
}
|
||||
|
||||
return $changesList
|
||||
|
||||
@@ -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,9 +66,7 @@ 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'
|
||||
}
|
||||
$script:UndoFeatureLabelLookup[$feature.FeatureId] = Get-Translation -Key $feature.FeatureId -Field 'UndoLabel' -Section 'Features'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,7 +242,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
|
||||
@@ -353,33 +351,10 @@ function New-DynamicTweakControls {
|
||||
}
|
||||
foreach ($f in $featuresJson.Features) { if ($f.Category) { $categoriesPresent[$f.Category] = $true } }
|
||||
|
||||
# Create cards in the order defined in Features.json Categories (if present)
|
||||
$orderedCategories = @()
|
||||
if ($featuresJson.Categories) {
|
||||
foreach ($c in $featuresJson.Categories) {
|
||||
$categoryName = if ($c -is [string]) { $c } else { $c.Name }
|
||||
if ($categoriesPresent.ContainsKey($categoryName)) {
|
||||
# Store the full category object (or create one with default icon for string categories).
|
||||
# A category without its own CategoryId falls back to its Name, same as before CategoryId existed.
|
||||
$categoryObj = if ($c -is [string]) {
|
||||
@{Name = $c; CategoryId = $c; Icon = '' }
|
||||
}
|
||||
elseif (-not $c.CategoryId) {
|
||||
@{Name = $c.Name; CategoryId = $c.Name; Icon = $c.Icon }
|
||||
}
|
||||
else {
|
||||
$c
|
||||
}
|
||||
$orderedCategories += $categoryObj
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
# For backward compatibility, create category objects from keys
|
||||
foreach ($catName in $categoriesPresent.Keys) {
|
||||
$orderedCategories += @{Name = $catName; CategoryId = $catName; Icon = '' }
|
||||
}
|
||||
}
|
||||
# Create cards in the order defined in Features.json Categories.
|
||||
$orderedCategories = @($featuresJson.Categories | Where-Object {
|
||||
$categoriesPresent.ContainsKey($_.Name)
|
||||
})
|
||||
|
||||
# Build a FeatureId -> feature lookup for version filtering in groups
|
||||
$featureMap = @{}
|
||||
@@ -482,7 +457,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
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
.DESCRIPTION
|
||||
Combines parameter keys from both forward and undo selections, removes duplicates,
|
||||
and returns the feature label that should be shown to users. Undo selections use
|
||||
UndoLabel when available.
|
||||
UndoLabel.
|
||||
#>
|
||||
function Get-RebootFeatureLabels {
|
||||
$rebootFeatureLabels = [System.Collections.Generic.List[string]]::new()
|
||||
@@ -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' }
|
||||
$labelField = if ($isUndo) { 'UndoLabel' } else { 'Label' }
|
||||
$displayLabel = Get-Translation -Key $paramKey -Field $labelField -Section 'Features'
|
||||
|
||||
if (-not [string]::IsNullOrWhiteSpace([string]$displayLabel)) {
|
||||
[void]$rebootFeatureLabels.Add([string]$displayLabel)
|
||||
|
||||
Reference in New Issue
Block a user