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
This commit is contained in:
3 files changed
+48
-2
No files matched your search
@@ -56,4 +56,10 @@ public static class Formatting
|
||||
|
||||
/// <summary>Camera wall-clock date in the culture's short format.</summary>
|
||||
public static string Date(DateTime wallClock) => wallClock.ToString("d", Loc.Culture);
|
||||
|
||||
/// <summary>
|
||||
/// A path, address or fingerprint kept left to right inside right-to-left text (a Unicode left-to-right embedding),
|
||||
/// so its separators and digits stay in place; it reads unchanged in left-to-right languages.
|
||||
/// </summary>
|
||||
public static string LeftToRight(string text) => "" + text + "";
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Automation;
|
||||
using System.Windows.Automation.Peers;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Titano.App.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// A status line screen readers announce when it changes (a live region): <c>LiveRegion.Text</c> becomes the element's
|
||||
/// accessible name and every later change raises <see cref="AutomationEvents.LiveRegionChanged"/>. The element's
|
||||
/// <see cref="AutomationProperties.LiveSettingProperty"/> (Polite, or Assertive for errors) must be set as well.
|
||||
/// </summary>
|
||||
public static class LiveRegion
|
||||
{
|
||||
public static readonly DependencyProperty TextProperty = DependencyProperty.RegisterAttached(
|
||||
"Text", typeof(string), typeof(LiveRegion), new PropertyMetadata(null, OnTextChanged));
|
||||
|
||||
public static string? GetText(DependencyObject element) => (string?)element.GetValue(TextProperty);
|
||||
|
||||
public static void SetText(DependencyObject element, string? value) => element.SetValue(TextProperty, value);
|
||||
|
||||
private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is not FrameworkElement element) return;
|
||||
AutomationProperties.SetName(element, (string?)e.NewValue ?? string.Empty);
|
||||
// The first value arrives with the screen: only what changes while it is shown is announced, once layout has shown
|
||||
// it (a status that appears with its text is still collapsed when the text arrives).
|
||||
if (!element.IsLoaded || e.NewValue is null || !AutomationPeer.ListenerExists(AutomationEvents.LiveRegionChanged)) return;
|
||||
element.Dispatcher.InvokeAsync(() => UIElementAutomationPeer.CreatePeerForElement(element)?.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged),
|
||||
DispatcherPriority.Background);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,15 @@ 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)
|
||||
{
|
||||
@@ -25,8 +34,7 @@ public static class UiLanguage
|
||||
Loc.SetCulture(culture);
|
||||
if (Application.Current is { } app)
|
||||
{
|
||||
foreach (Window window in app.Windows)
|
||||
window.FlowDirection = Loc.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
|
||||
foreach (Window window in app.Windows) window.FlowDirection = Direction;
|
||||
}
|
||||
return culture;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user