- Language: "System default" now reverts to the OS culture. SetCulture had
overwritten CultureInfo.CurrentUICulture, so "follow OS" resolved to the
last-picked language. LocalizationManager captures the OS culture once
(SystemCulture) and uses it for the follow-OS option (+ test).
- Dark-mode contrast:
- Console / command-preview boxes used MaterialDesignTextFieldBoxBackground,
which renders light in dark mode (shadowed by MaterialDesign2.Defaults, not
refreshed by runtime SetTheme) -> light text on light box. Switched to
MaterialDesignToolBarBackground, which follows the theme.
- "Confirm before Dangerous" was IsEnabled=False (dimmed to near-unreadable in
dark mode); now non-interactive (IsHitTestVisible/Focusable=False) at full
contrast with a lock icon.
- Danger badge text White -> near-black for AA contrast on the badge.
Verified by launching in Dark mode and capturing the console + Settings; 59 tests pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
78 lines
2.5 KiB
C#
78 lines
2.5 KiB
C#
using System.ComponentModel;
|
|
using System.Globalization;
|
|
using CommandForge.Wpf.Resources;
|
|
|
|
namespace CommandForge.Tests;
|
|
|
|
/// <summary>Verifies the live-localization source flips strings and notifies bindings on culture change.</summary>
|
|
public sealed class LocalizationManagerTests
|
|
{
|
|
[Fact]
|
|
public void SetCulture_FlipsIndexerLanguage()
|
|
{
|
|
var original = LocalizationManager.Instance.CurrentCulture;
|
|
try
|
|
{
|
|
LocalizationManager.Instance.SetCulture(new CultureInfo("en"));
|
|
var en = LocalizationManager.Instance["Menu_CheckForUpdates"];
|
|
|
|
LocalizationManager.Instance.SetCulture(new CultureInfo("vi"));
|
|
var vi = LocalizationManager.Instance["Menu_CheckForUpdates"];
|
|
|
|
Assert.False(string.IsNullOrEmpty(en));
|
|
Assert.False(string.IsNullOrEmpty(vi));
|
|
Assert.NotEqual(en, vi); // EN and VI resources differ for this key
|
|
}
|
|
finally
|
|
{
|
|
LocalizationManager.Instance.SetCulture(original);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void SystemCulture_IsStable_AfterCultureChange()
|
|
{
|
|
var original = LocalizationManager.Instance.CurrentCulture;
|
|
try
|
|
{
|
|
// "Follow OS" must keep resolving to the OS culture, not the last-selected language.
|
|
var systemBefore = LocalizationManager.Instance.SystemCulture.Name;
|
|
LocalizationManager.Instance.SetCulture(new CultureInfo("vi"));
|
|
Assert.Equal(systemBefore, LocalizationManager.Instance.SystemCulture.Name);
|
|
}
|
|
finally
|
|
{
|
|
LocalizationManager.Instance.SetCulture(original);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void SetCulture_RaisesItemBracketPropertyChanged()
|
|
{
|
|
var original = LocalizationManager.Instance.CurrentCulture;
|
|
try
|
|
{
|
|
LocalizationManager.Instance.SetCulture(new CultureInfo("en"));
|
|
|
|
string? changed = null;
|
|
void Handler(object? sender, PropertyChangedEventArgs e)
|
|
{
|
|
if (e.PropertyName == "Item[]")
|
|
{
|
|
changed = e.PropertyName;
|
|
}
|
|
}
|
|
|
|
LocalizationManager.Instance.PropertyChanged += Handler;
|
|
LocalizationManager.Instance.SetCulture(new CultureInfo("vi"));
|
|
LocalizationManager.Instance.PropertyChanged -= Handler;
|
|
|
|
Assert.Equal("Item[]", changed);
|
|
}
|
|
finally
|
|
{
|
|
LocalizationManager.Instance.SetCulture(original);
|
|
}
|
|
}
|
|
}
|