Files
Chronos/src/Titano.App/Infrastructure/UiLanguage.cs
T
Claude baf3c6bddd fix(app): every window follows the reading direction; live regions and left-to-right text
Windows created after the language was applied (the main window at start, every
dialog) now take FlowDirection from the current culture when they load, so an
Arabic or Hebrew UI stays mirrored after a restart and in dialogs. Adds
LiveRegion.Text (announces status changes to screen readers) and
Formatting.LeftToRight (keeps paths, addresses and fingerprints in order inside
right-to-left text).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-03 17:23:33 +00:00

42 lines
1.6 KiB
C#

using System.Globalization;
using System.Windows;
using Titano.Core.Localization;
namespace Titano.App.Infrastructure;
/// <summary>Switches the UI language at run time without restart (BRIEF §16), mirroring right-to-left languages.</summary>
public static class UiLanguage
{
static UiLanguage()
{
// Windows created later (the main window at start, every dialog) take the reading direction when they load.
EventManager.RegisterClassHandler(typeof(Window), FrameworkElement.LoadedEvent, new RoutedEventHandler((sender, _) => ((Window)sender).FlowDirection = Direction));
}
/// <summary>The reading direction of the current language.</summary>
public static FlowDirection Direction => Loc.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
/// <summary>Applies <paramref name="code"/> (or the OS language when null) and returns the culture in use.</summary>
public static CultureInfo Apply(string? code)
{
CultureInfo requested;
try
{
requested = code is null ? CultureInfo.CurrentUICulture : CultureInfo.GetCultureInfo(code);
}
catch (CultureNotFoundException)
{
requested = CultureInfo.CurrentUICulture;
}
var culture = Languages.BestMatch(requested);
CultureInfo.DefaultThreadCurrentUICulture = culture;
CultureInfo.CurrentUICulture = culture;
Loc.SetCulture(culture);
if (Application.Current is { } app)
{
foreach (Window window in app.Windows) window.FlowDirection = Direction;
}
return culture;
}
}