mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-10-08 06:26:45 +00:00
Add localization framework for the GUI (en-US baseline) (#764)
Credit to @jmolinap2 for their work in #643, which was used as inspiration.
This commit is contained in:
@@ -15,7 +15,7 @@ function Confirm-UnsafeAppRemoval {
|
||||
|
||||
# Microsoft Store warning
|
||||
if ($SelectedApps -contains "Microsoft.WindowsStore") {
|
||||
$result = Show-MessageBox -Message 'Are you sure that you wish to uninstall the Microsoft Store? This app cannot easily be reinstalled.' -Title 'Are you sure?' -Button 'YesNo' -Icon 'Warning' -Owner $Owner
|
||||
$result = Show-MessageBox -Message (Get-Translation -Key 'ConfirmRemoveStoreMessage') -Title (Get-Translation -Key 'ConfirmTitle') -Button 'YesNo' -Icon 'Warning' -Owner $Owner
|
||||
|
||||
if ($result -ne 'Yes') {
|
||||
return $false
|
||||
@@ -24,7 +24,7 @@ function Confirm-UnsafeAppRemoval {
|
||||
|
||||
# Windows Terminal warning
|
||||
if ($SelectedApps -contains "Microsoft.WindowsTerminal") {
|
||||
$result = Show-MessageBox -Message 'Are you sure that you wish to remove Windows Terminal? Windows Terminal is the default command-line app for Windows. Ensure you are not running Win11Debloat via Windows Terminal before proceeding to avoid a mid-process failure.' -Title 'Are you sure?' -Button 'YesNo' -Icon 'Warning' -Owner $Owner
|
||||
$result = Show-MessageBox -Message (Get-Translation -Key 'ConfirmRemoveTerminalMessage') -Title (Get-Translation -Key 'ConfirmTitle') -Button 'YesNo' -Icon 'Warning' -Owner $Owner
|
||||
|
||||
if ($result -ne 'Yes') {
|
||||
return $false
|
||||
|
||||
@@ -10,37 +10,37 @@ function Get-FriendlyRegistryBackupTarget {
|
||||
)
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($Target)) {
|
||||
return 'Unknown'
|
||||
return Get-Translation -Key 'RestoreTargetUnknown'
|
||||
}
|
||||
|
||||
if ($Target -eq 'DefaultUserProfile') {
|
||||
return 'Default user profile'
|
||||
return Get-Translation -Key 'RestoreTargetDefaultUserProfile'
|
||||
}
|
||||
|
||||
if ($Target -eq 'CurrentUser') {
|
||||
return 'Current user'
|
||||
return Get-Translation -Key 'RestoreTargetCurrentUser'
|
||||
}
|
||||
|
||||
if ($Target -eq 'AllUsers') {
|
||||
return 'All users'
|
||||
return Get-Translation -Key 'RestoreTargetAllUsers'
|
||||
}
|
||||
|
||||
if ($Target -like 'CurrentUser:*') {
|
||||
$userName = $Target.Substring(12)
|
||||
if ([string]::IsNullOrWhiteSpace($userName)) {
|
||||
return 'Current user'
|
||||
return Get-Translation -Key 'RestoreTargetCurrentUser'
|
||||
}
|
||||
|
||||
return "Current user ($userName)"
|
||||
return Get-Translation -Key 'RestoreTargetCurrentUserNamed' -FormatArgs @($userName)
|
||||
}
|
||||
|
||||
if ($Target -like 'User:*') {
|
||||
$userName = $Target.Substring(5)
|
||||
if ([string]::IsNullOrWhiteSpace($userName)) {
|
||||
return 'User'
|
||||
return Get-Translation -Key 'RestoreTargetUser'
|
||||
}
|
||||
|
||||
return "User ($userName)"
|
||||
return Get-Translation -Key 'RestoreTargetUserNamed' -FormatArgs @($userName)
|
||||
}
|
||||
|
||||
return $Target
|
||||
|
||||
@@ -15,7 +15,7 @@ function Get-RebootFeatureLabels {
|
||||
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) { $feature.UndoLabel } else { $feature.Label }
|
||||
$displayLabel = if ($isUndo -and $feature.UndoLabel) { Get-Translation -Key $paramKey -Field 'UndoLabel' -Section 'Features' } else { Get-Translation -Key $paramKey -Field 'Label' -Section 'Features' }
|
||||
|
||||
if (-not [string]::IsNullOrWhiteSpace([string]$displayLabel)) {
|
||||
[void]$rebootFeatureLabels.Add([string]$displayLabel)
|
||||
|
||||
@@ -14,24 +14,24 @@ function Test-ConfigConsistency {
|
||||
param($Config)
|
||||
|
||||
if (-not $Config) {
|
||||
return 'Configuration is empty or could not be read.'
|
||||
return Get-Translation -Key 'ConfigEmptyOrUnreadable'
|
||||
}
|
||||
|
||||
if (-not $Config.Version) {
|
||||
return 'Configuration is missing a Version field.'
|
||||
return Get-Translation -Key 'ConfigMissingVersion'
|
||||
}
|
||||
|
||||
if (-not $Config.Apps -and -not $Config.Tweaks -and -not $Config.Deployment) {
|
||||
return 'The configuration file contains no importable data.'
|
||||
return Get-Translation -Key 'ConfigNoImportableData'
|
||||
}
|
||||
|
||||
if ($null -ne $Config.Apps) {
|
||||
if ($Config.Apps -isnot [string] -and $Config.Apps -isnot [System.Collections.IEnumerable]) {
|
||||
return 'Configuration Apps entries must be strings.'
|
||||
return Get-Translation -Key 'ConfigAppsMustBeStrings'
|
||||
}
|
||||
foreach ($app in @($Config.Apps)) {
|
||||
if ($app -isnot [string]) {
|
||||
return 'Configuration Apps entries must be strings.'
|
||||
return Get-Translation -Key 'ConfigAppsMustBeStrings'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,13 +41,13 @@ function Test-ConfigConsistency {
|
||||
if ($null -eq $category) { continue }
|
||||
|
||||
if ($category -is [string] -or $category -isnot [System.Collections.IEnumerable]) {
|
||||
return "Configuration $categoryName entries must contain Name and Value properties."
|
||||
return Get-Translation -Key 'ConfigEntriesMustHaveNameAndValue' -FormatArgs @($categoryName)
|
||||
}
|
||||
foreach ($setting in @($category)) {
|
||||
$hasName = if ($setting -is [System.Collections.IDictionary]) { $setting.Contains('Name') } else { $null -ne $setting.PSObject.Properties['Name'] }
|
||||
$hasValue = if ($setting -is [System.Collections.IDictionary]) { $setting.Contains('Value') } else { $null -ne $setting.PSObject.Properties['Value'] }
|
||||
if (-not $setting -or -not $hasName -or -not $hasValue -or $setting.Name -isnot [string] -or [string]::IsNullOrWhiteSpace($setting.Name)) {
|
||||
return "Configuration $categoryName entries must contain Name and Value properties."
|
||||
return Get-Translation -Key 'ConfigEntriesMustHaveNameAndValue' -FormatArgs @($categoryName)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,31 +65,31 @@ function Test-ConfigConsistency {
|
||||
$scopeIndex = $null
|
||||
if ($hasScope) {
|
||||
if (-not [int]::TryParse("$($lookup['AppRemovalScopeIndex'])", [ref]$scopeIndex) -or $scopeIndex -notin @(0, 1, 2)) {
|
||||
return 'AppRemovalScopeIndex must be a supported numeric value (0, 1, or 2).'
|
||||
return Get-Translation -Key 'ConfigInvalidAppRemovalScopeIndex'
|
||||
}
|
||||
}
|
||||
|
||||
$userIndex = $null
|
||||
if ($hasUser) {
|
||||
if (-not [int]::TryParse("$($lookup['UserSelectionIndex'])", [ref]$userIndex) -or $userIndex -notin @(0, 1, 2)) {
|
||||
return 'UserSelectionIndex must be a supported numeric value (0, 1, or 2).'
|
||||
return Get-Translation -Key 'ConfigInvalidUserSelectionIndex'
|
||||
}
|
||||
}
|
||||
|
||||
# "Current user only" (index 1) is only valid together with "Current User" (index 0)
|
||||
if ($hasScope -and $scopeIndex -eq 1) {
|
||||
if (-not $hasUser -or $userIndex -ne 0) {
|
||||
return "App removal scope 'Current user only' (AppRemovalScopeIndex 1) requires the deployment target 'Current User' (UserSelectionIndex 0)."
|
||||
return Get-Translation -Key 'ConfigScopeRequiresCurrentUserTarget'
|
||||
}
|
||||
}
|
||||
|
||||
# "Target user only" (index 2) is only valid together with "Other User" (index 1)
|
||||
if ($hasScope -and $scopeIndex -eq 2) {
|
||||
if (-not $hasUser -or $userIndex -ne 1) {
|
||||
return "App removal scope 'Target user only' (AppRemovalScopeIndex 2) requires the deployment target 'Other User' (UserSelectionIndex 1)."
|
||||
return Get-Translation -Key 'ConfigScopeRequiresOtherUserTarget'
|
||||
}
|
||||
if (-not $lookup.ContainsKey('OtherUsername') -or [string]::IsNullOrWhiteSpace("$($lookup['OtherUsername'])")) {
|
||||
return "App removal scope 'Target user only' (AppRemovalScopeIndex 2) requires an 'OtherUsername' value."
|
||||
return Get-Translation -Key 'ConfigScopeRequiresOtherUsername'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Validates a username for the "apply changes to another user" deployment target.
|
||||
|
||||
.DESCRIPTION
|
||||
Rejects an empty name, the current user's own name (that's the "Current User" option
|
||||
instead), and a name with no matching local profile, in that order.
|
||||
|
||||
.OUTPUTS
|
||||
PSCustomObject with IsValid (bool), UserName (the trimmed input), and Message (a
|
||||
translated string describing the validation result, success or failure alike).
|
||||
#>
|
||||
function Test-TargetUserName {
|
||||
param(
|
||||
[AllowNull()]
|
||||
@@ -11,7 +23,7 @@ function Test-TargetUserName {
|
||||
return [PSCustomObject]@{
|
||||
IsValid = $false
|
||||
UserName = $normalizedUserName
|
||||
Message = 'Please enter a username'
|
||||
Message = Get-Translation -Key 'UsernameValidationEmpty'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +31,7 @@ function Test-TargetUserName {
|
||||
return [PSCustomObject]@{
|
||||
IsValid = $false
|
||||
UserName = $normalizedUserName
|
||||
Message = "Cannot enter your own username, use 'Current User' option instead"
|
||||
Message = Get-Translation -Key 'UsernameValidationOwnUsername'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,13 +39,13 @@ function Test-TargetUserName {
|
||||
return [PSCustomObject]@{
|
||||
IsValid = $false
|
||||
UserName = $normalizedUserName
|
||||
Message = 'User not found, please enter a valid username'
|
||||
Message = Get-Translation -Key 'UsernameValidationNotFound'
|
||||
}
|
||||
}
|
||||
|
||||
return [PSCustomObject]@{
|
||||
IsValid = $true
|
||||
UserName = $normalizedUserName
|
||||
Message = "User found: $normalizedUserName"
|
||||
Message = Get-Translation -Key 'UsernameValidationFound' -FormatArgs @($normalizedUserName)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user