Skip to content

Free, open-source Windows optimization tool for performance, privacy, and simplicity.

fix(i18n): refresh stale localized text on runtime language switch

fatDuck746cdf376e6e
diff --git a/optimizerDuck.Test/Domain/Conditions/ConditionTests.cs b/optimizerDuck.Test/Domain/Conditions/ConditionTests.cs
index 7023be3..0cf5f91 100644
--- a/optimizerDuck.Test/Domain/Conditions/ConditionTests.cs
+++ b/optimizerDuck.Test/Domain/Conditions/ConditionTests.cs
@@ -52,7 +52,7 @@ public class ConditionTests
BuildNumber = build,
Edition = "Pro",
Architecture = "64-bit",
- DeviceType = "Desktop",
+ DeviceType = DeviceKind.Desktop,
InstallDate = "2024-01-01",
LastBootUpTime = "2024-01-01 00:00",
},
diff --git a/optimizerDuck/Common/Converters/DeviceKindConverter.cs b/optimizerDuck/Common/Converters/DeviceKindConverter.cs
new file mode 100644
index 0000000..47dbf8c
--- /dev/null
+++ b/optimizerDuck/Common/Converters/DeviceKindConverter.cs
@@ -0,0 +1,32 @@
+using System.Globalization;
+using System.Windows.Data;
+using optimizerDuck.Services.Configuration;
+using optimizerDuck.Services.System;
+
+namespace optimizerDuck.Common.Converters;
+
+/// <summary>Converts a <see cref="DeviceKind"/> to its localized display text.</summary>
+public class DeviceKindConverter : IValueConverter
+{
+ public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
+ {
+ return value is DeviceKind kind
+ ? kind switch
+ {
+ DeviceKind.Desktop => Loc.Instance["Dashboard.SystemInfo.Os.DeviceType.Desktop"],
+ DeviceKind.Laptop => Loc.Instance["Dashboard.SystemInfo.Os.DeviceType.Laptop"],
+ _ => Loc.Instance["Common.Unknown"],
+ }
+ : Loc.Instance["Common.Unknown"];
+ }
+
+ public object ConvertBack(
+ object? value,
+ Type targetType,
+ object? parameter,
+ CultureInfo culture
+ )
+ {
+ throw new NotSupportedException();
+ }
+}
diff --git a/optimizerDuck/Services/System/SystemInfoService.cs b/optimizerDuck/Services/System/SystemInfoService.cs
index c22b1e7..fd9315c 100644
--- a/optimizerDuck/Services/System/SystemInfoService.cs
+++ b/optimizerDuck/Services/System/SystemInfoService.cs
@@ -49,6 +49,22 @@ public enum CpuVendor
AMD,
}
+/// <summary>
+/// Specifies the device form factor inferred from chassis information.
+/// Stored raw (never localized) so the display text can re-resolve on language change.
+/// </summary>
+public enum DeviceKind
+{
+ /// <summary>Unknown or unrecognized device type.</summary>
+ Unknown,
+
+ /// <summary>Desktop, tower, or other stationary machine.</summary>
+ Desktop,
+
+ /// <summary>Laptop, notebook, or other portable machine.</summary>
+ Laptop,
+}
+
/// <summary>
/// Represents information about a GPU.
/// </summary>
@@ -352,7 +368,7 @@ public sealed record OsInfo
BuildNumber = Loc.Instance["Common.Unknown"],
Edition = Loc.Instance["Common.Unknown"],
Architecture = Loc.Instance["Common.Unknown"],
- DeviceType = Loc.Instance["Common.Unknown"],
+ DeviceType = DeviceKind.Unknown,
InstallDate = Loc.Instance["Common.Unknown"],
LastBootUpTime = Loc.Instance["Common.Unknown"],
};
@@ -383,9 +399,9 @@ public sealed record OsInfo
public required string Architecture { get; init; }
/// <summary>
- /// The device type inferred from chassis information (e.g., "Desktop", "Laptop").
+ /// The device form factor inferred from chassis information.
/// </summary>
- public required string DeviceType { get; init; }
+ public required DeviceKind DeviceType { get; init; }
/// <summary>
/// The OS install date.
@@ -2060,21 +2076,21 @@ internal static class OsProvider
};
}
- private static string GetDeviceType()
+ private static DeviceKind GetDeviceType()
{
var chassis = WmiHelper.GetFirst("SELECT ChassisTypes FROM Win32_SystemEnclosure");
if (chassis == null)
- return "Unknown";
+ return DeviceKind.Unknown;
try
{
return chassis["ChassisTypes"] is ushort[] { Length: > 0 } types
? MapChassisType(types)
- : "Unknown";
+ : DeviceKind.Unknown;
}
catch
{
- return "Unknown";
+ return DeviceKind.Unknown;
}
finally
{
@@ -2082,13 +2098,13 @@ internal static class OsProvider
}
}
- private static string MapChassisType(IEnumerable<ushort> types)
+ private static DeviceKind MapChassisType(IEnumerable<ushort> types)
{
foreach (var type in types)
switch (type)
{
case 8 or 9 or 10 or 11 or 14 or 30 or 31 or 32:
- return Loc.Instance["Dashboard.SystemInfo.Os.DeviceType.Laptop"];
+ return DeviceKind.Laptop;
case >= 1
and <= 7
@@ -2098,10 +2114,10 @@ internal static class OsProvider
and <= 29
or >= 33
and <= 36:
- return Loc.Instance["Dashboard.SystemInfo.Os.DeviceType.Desktop"];
+ return DeviceKind.Desktop;
}
- return Loc.Instance["Common.Unknown"];
+ return DeviceKind.Unknown;
}
private static string FormatWmiDateTime(string wmiDate)
diff --git a/optimizerDuck/UI/Pages/DashboardPage.xaml b/optimizerDuck/UI/Pages/DashboardPage.xaml
index da9b641..b39c6d7 100644
--- a/optimizerDuck/UI/Pages/DashboardPage.xaml
+++ b/optimizerDuck/UI/Pages/DashboardPage.xaml
@@ -176,7 +176,7 @@
Padding="6,2"
Background="{DynamicResource CardBackgroundFillColorSecondaryBrush}"
CornerRadius="{StaticResource CornerRadiusSmall}">
- <ui:TextBlock FontTypography="Caption" Text="{Binding ViewModel.SystemInfo.Os.DeviceType}" />
+ <ui:TextBlock FontTypography="Caption" Text="{Binding ViewModel.SystemInfo.Os.DeviceType, Converter={StaticResource DeviceKindConverter}}" />
</Border>
<Border
Margin="0,0,4,4"
diff --git a/optimizerDuck/UI/Styles/Converters.xaml b/optimizerDuck/UI/Styles/Converters.xaml
index d251c93..b5b4ba2 100644
--- a/optimizerDuck/UI/Styles/Converters.xaml
+++ b/optimizerDuck/UI/Styles/Converters.xaml
@@ -41,6 +41,7 @@
<converters:MBToGBConverter x:Key="MBToGBConverter" />
<converters:MinusNumberConverter x:Key="MinusNumberConverter" />
<converters:MinusNumberConverter x:Key="MinusOneConverter" NumberToMinus="1" />
+ <converters:DeviceKindConverter x:Key="DeviceKindConverter" />
<!-- Theme & Recommendation Converters -->
<converters:ThemeToGitHubIconConverter x:Key="ThemeToGitHubIconConverter" />
diff --git a/optimizerDuck/UI/ViewModels/Customize/CustomizeItemViewModel.cs b/optimizerDuck/UI/ViewModels/Customize/CustomizeItemViewModel.cs
index 448f25b..17a1239 100644
--- a/optimizerDuck/UI/ViewModels/Customize/CustomizeItemViewModel.cs
+++ b/optimizerDuck/UI/ViewModels/Customize/CustomizeItemViewModel.cs
@@ -1,3 +1,4 @@
+using System.Globalization;
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -146,6 +147,24 @@ public partial class CustomizeItemViewModel(
Options = options;
}
+ /// <summary>
+ /// Re-publishes dropdown options so their display text re-resolves in the
+ /// new language. Option values are unchanged; only <c>Display</c> refreshes.
+ /// </summary>
+ protected override void OnLanguageChanged(CultureInfo newCulture)
+ {
+ if (!_hasLoaded)
+ return;
+ try
+ {
+ Options = setting.Options;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogWarning(ex, "Failed to refresh options after language change");
+ }
+ }
+
private static bool HasSameOptionValues(
IReadOnlyList<SettingOption>? a,
IReadOnlyList<SettingOption>? b
diff --git a/optimizerDuck/UI/ViewModels/Dialogs/LegalDialogViewModel.cs b/optimizerDuck/UI/ViewModels/Dialogs/LegalDialogViewModel.cs
index 44c57dd..ebeb988 100644
--- a/optimizerDuck/UI/ViewModels/Dialogs/LegalDialogViewModel.cs
+++ b/optimizerDuck/UI/ViewModels/Dialogs/LegalDialogViewModel.cs
@@ -2,6 +2,7 @@ using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Windows;
+using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.Logging;
@@ -62,8 +63,16 @@ public partial class LegalDialogViewModel(
if (value == Loc.CurrentCulture.Name)
return;
- Loc.Instance.ChangeCulture(new CultureInfo(value));
- logger.LogInformation("Language changed to {Language} from LegalDialog", value);
+ Mouse.OverrideCursor = Cursors.Wait;
+ try
+ {
+ Loc.Instance.ChangeCulture(new CultureInfo(value));
+ logger.LogInformation("Language changed to {Language} from LegalDialog", value);
+ }
+ finally
+ {
+ Mouse.OverrideCursor = null;
+ }
}
partial void OnCurrentApplicationThemeChanged(
diff --git a/optimizerDuck/UI/ViewModels/Pages/SettingsViewModel.cs b/optimizerDuck/UI/ViewModels/Pages/SettingsViewModel.cs
index ae718fb..594c5d2 100644
--- a/optimizerDuck/UI/ViewModels/Pages/SettingsViewModel.cs
+++ b/optimizerDuck/UI/ViewModels/Pages/SettingsViewModel.cs
@@ -2,6 +2,7 @@ using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Windows;
+using System.Windows.Input;
using System.Windows.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -366,8 +367,15 @@ public partial class SettingsViewModel(
if (value == Loc.CurrentCulture.Name)
return;
- // Apply the new culture immediately so the entire UI refreshes without restart.
- Loc.Instance.ChangeCulture(new CultureInfo(value));
+ Mouse.OverrideCursor = Cursors.Wait;
+ try
+ {
+ Loc.Instance.ChangeCulture(new CultureInfo(value));
+ }
+ finally
+ {
+ Mouse.OverrideCursor = null;
+ }
}
partial void OnCurrentApplicationThemeChanged(