Rework locale handler and fix remaining RTL issues

window handler was being duplicated, wouldn't apply for system default language nor on initial installation, winforms progress bar not following RTL changes
This commit is contained in:
pizzaboxer 2024-07-03 12:08:46 +04:00
parent a6d8e45596
commit 3d3684c248
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
7 changed files with 47 additions and 38 deletions

View File

@ -111,7 +111,7 @@ namespace Bloxstrap
{ {
const string LOG_IDENT = "App::OnStartup"; const string LOG_IDENT = "App::OnStartup";
Locale.CurrentCulture = Thread.CurrentThread.CurrentUICulture; Locale.Initialize();
base.OnStartup(e); base.OnStartup(e);
@ -144,7 +144,8 @@ namespace Bloxstrap
Settings.Load(); Settings.Load();
State.Load(); State.Load();
FastFlags.Load(); FastFlags.Load();
Locale.Set();
Locale.Set(Settings.Prop.Locale);
} }
LaunchSettings.ParseRoblox(); LaunchSettings.ParseRoblox();

View File

@ -6,7 +6,7 @@ namespace Bloxstrap
{ {
internal static class Locale internal static class Locale
{ {
public static CultureInfo CurrentCulture = CultureInfo.InvariantCulture; public static CultureInfo CurrentCulture { get; private set; } = CultureInfo.InvariantCulture;
public static bool RightToLeft { get; private set; } = false; public static bool RightToLeft { get; private set; } = false;
@ -67,45 +67,47 @@ namespace Bloxstrap
return languages; return languages;
} }
public static void Set() public static void Set(string identifier)
{ {
string identifier = App.Settings.Prop.Locale;
if (!SupportedLocales.ContainsKey(identifier)) if (!SupportedLocales.ContainsKey(identifier))
identifier = "nil"; identifier = "nil";
if (identifier == "nil") if (identifier == "nil")
return;
CurrentCulture = new CultureInfo(identifier);
CultureInfo.DefaultThreadCurrentUICulture = CurrentCulture;
Thread.CurrentThread.CurrentUICulture = CurrentCulture;
RoutedEventHandler? handler = null;
if (identifier == "ar" || identifier == "he")
{ {
RightToLeft = true; CurrentCulture = Thread.CurrentThread.CurrentUICulture;
}
else
{
CurrentCulture = new CultureInfo(identifier);
handler = new((sender, _) => CultureInfo.DefaultThreadCurrentUICulture = CurrentCulture;
Thread.CurrentThread.CurrentUICulture = CurrentCulture;
}
RightToLeft = CurrentCulture.Name.StartsWith("ar") || CurrentCulture.Name.StartsWith("he");
}
public static void Initialize()
{
Set("nil");
// https://supportcenter.devexpress.com/ticket/details/t905790/is-there-a-way-to-set-right-to-left-mode-in-wpf-for-the-whole-application
EventManager.RegisterClassHandler(typeof(Window), FrameworkElement.LoadedEvent, new RoutedEventHandler((sender, _) =>
{
var window = (Window)sender;
if (RightToLeft)
{ {
var window = (Window)sender;
window.FlowDirection = FlowDirection.RightToLeft; window.FlowDirection = FlowDirection.RightToLeft;
if (window.ContextMenu is not null) if (window.ContextMenu is not null)
window.ContextMenu.FlowDirection = FlowDirection.RightToLeft; window.ContextMenu.FlowDirection = FlowDirection.RightToLeft;
}); }
} else if (CurrentCulture.Name.StartsWith("th"))
else if (identifier == "th") {
{ window.FontFamily = new System.Windows.Media.FontFamily(new Uri("pack://application:,,,/Resources/Fonts/"), "./#Noto Sans Thai");
handler = new((window, _) => ((Window)window).FontFamily = new System.Windows.Media.FontFamily(new Uri("pack://application:,,,/Resources/Fonts/"), "./#Noto Sans Thai")); }
} }));
// https://supportcenter.devexpress.com/ticket/details/t905790/is-there-a-way-to-set-right-to-left-mode-in-wpf-for-the-whole-application
if (handler is not null)
EventManager.RegisterClassHandler(typeof(Window), FrameworkElement.LoadedEvent, handler);
} }
} }
} }

View File

@ -100,11 +100,6 @@ namespace Bloxstrap.UI.Elements.Bootstrapper.Base
this.RightToLeft = RightToLeft.Yes; this.RightToLeft = RightToLeft.Yes;
this.RightToLeftLayout = true; this.RightToLeftLayout = true;
} }
else
{
this.RightToLeft = RightToLeft.No;
this.RightToLeftLayout = false;
}
} }
#region WinForms event handlers #region WinForms event handlers

View File

@ -47,6 +47,9 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
ScaleWindow(); ScaleWindow();
SetupDialog(); SetupDialog();
this.ProgressBar.RightToLeft = this.RightToLeft;
this.ProgressBar.RightToLeftLayout = this.RightToLeftLayout;
} }
private void LegacyDialog2008_Load(object sender, EventArgs e) private void LegacyDialog2008_Load(object sender, EventArgs e)

View File

@ -47,6 +47,9 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
ScaleWindow(); ScaleWindow();
SetupDialog(); SetupDialog();
this.ProgressBar.RightToLeft = this.RightToLeft;
this.ProgressBar.RightToLeftLayout = this.RightToLeftLayout;
} }
private void LegacyDialog2011_Load(object sender, EventArgs e) private void LegacyDialog2011_Load(object sender, EventArgs e)

View File

@ -57,6 +57,9 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
this.IconBox.BackgroundImage = App.Settings.Prop.BootstrapperIcon.GetIcon().GetSized(128, 128).ToBitmap(); this.IconBox.BackgroundImage = App.Settings.Prop.BootstrapperIcon.GetIcon().GetSized(128, 128).ToBitmap();
SetupDialog(); SetupDialog();
this.ProgressBar.RightToLeft = this.RightToLeft;
this.ProgressBar.RightToLeftLayout = this.RightToLeftLayout;
} }
private void ButtonCancel_MouseEnter(object sender, EventArgs e) private void ButtonCancel_MouseEnter(object sender, EventArgs e)

View File

@ -21,8 +21,10 @@ namespace Bloxstrap.UI.ViewModels.Dialogs
private void SetLocale() private void SetLocale()
{ {
App.Settings.Prop.Locale = Locale.GetIdentifierFromName(SelectedLanguage); string identifier = Locale.GetIdentifierFromName(SelectedLanguage);
Locale.Set();
Locale.Set(identifier);
App.Settings.Prop.Locale = identifier;
CloseRequestEvent?.Invoke(this, new()); CloseRequestEvent?.Invoke(this, new());
} }