mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
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:
parent
a6d8e45596
commit
3d3684c248
@ -111,7 +111,7 @@ namespace Bloxstrap
|
||||
{
|
||||
const string LOG_IDENT = "App::OnStartup";
|
||||
|
||||
Locale.CurrentCulture = Thread.CurrentThread.CurrentUICulture;
|
||||
Locale.Initialize();
|
||||
|
||||
base.OnStartup(e);
|
||||
|
||||
@ -144,7 +144,8 @@ namespace Bloxstrap
|
||||
Settings.Load();
|
||||
State.Load();
|
||||
FastFlags.Load();
|
||||
Locale.Set();
|
||||
|
||||
Locale.Set(Settings.Prop.Locale);
|
||||
}
|
||||
|
||||
LaunchSettings.ParseRoblox();
|
||||
|
@ -6,7 +6,7 @@ namespace Bloxstrap
|
||||
{
|
||||
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;
|
||||
|
||||
@ -67,45 +67,47 @@ namespace Bloxstrap
|
||||
return languages;
|
||||
}
|
||||
|
||||
public static void Set()
|
||||
public static void Set(string identifier)
|
||||
{
|
||||
string identifier = App.Settings.Prop.Locale;
|
||||
|
||||
if (!SupportedLocales.ContainsKey(identifier))
|
||||
identifier = "nil";
|
||||
|
||||
if (identifier == "nil")
|
||||
return;
|
||||
|
||||
{
|
||||
CurrentCulture = Thread.CurrentThread.CurrentUICulture;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentCulture = new CultureInfo(identifier);
|
||||
|
||||
CultureInfo.DefaultThreadCurrentUICulture = CurrentCulture;
|
||||
Thread.CurrentThread.CurrentUICulture = CurrentCulture;
|
||||
}
|
||||
|
||||
RoutedEventHandler? handler = null;
|
||||
RightToLeft = CurrentCulture.Name.StartsWith("ar") || CurrentCulture.Name.StartsWith("he");
|
||||
}
|
||||
|
||||
if (identifier == "ar" || identifier == "he")
|
||||
public static void Initialize()
|
||||
{
|
||||
RightToLeft = true;
|
||||
Set("nil");
|
||||
|
||||
handler = new((sender, _) =>
|
||||
// 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)
|
||||
{
|
||||
window.FlowDirection = FlowDirection.RightToLeft;
|
||||
|
||||
if (window.ContextMenu is not null)
|
||||
window.ContextMenu.FlowDirection = FlowDirection.RightToLeft;
|
||||
});
|
||||
}
|
||||
else if (identifier == "th")
|
||||
else if (CurrentCulture.Name.StartsWith("th"))
|
||||
{
|
||||
handler = new((window, _) => ((Window)window).FontFamily = new System.Windows.Media.FontFamily(new Uri("pack://application:,,,/Resources/Fonts/"), "./#Noto Sans Thai"));
|
||||
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);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,11 +100,6 @@ namespace Bloxstrap.UI.Elements.Bootstrapper.Base
|
||||
this.RightToLeft = RightToLeft.Yes;
|
||||
this.RightToLeftLayout = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.RightToLeft = RightToLeft.No;
|
||||
this.RightToLeftLayout = false;
|
||||
}
|
||||
}
|
||||
|
||||
#region WinForms event handlers
|
||||
|
@ -47,6 +47,9 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
|
||||
|
||||
ScaleWindow();
|
||||
SetupDialog();
|
||||
|
||||
this.ProgressBar.RightToLeft = this.RightToLeft;
|
||||
this.ProgressBar.RightToLeftLayout = this.RightToLeftLayout;
|
||||
}
|
||||
|
||||
private void LegacyDialog2008_Load(object sender, EventArgs e)
|
||||
|
@ -47,6 +47,9 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
|
||||
|
||||
ScaleWindow();
|
||||
SetupDialog();
|
||||
|
||||
this.ProgressBar.RightToLeft = this.RightToLeft;
|
||||
this.ProgressBar.RightToLeftLayout = this.RightToLeftLayout;
|
||||
}
|
||||
|
||||
private void LegacyDialog2011_Load(object sender, EventArgs e)
|
||||
|
@ -57,6 +57,9 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
|
||||
this.IconBox.BackgroundImage = App.Settings.Prop.BootstrapperIcon.GetIcon().GetSized(128, 128).ToBitmap();
|
||||
|
||||
SetupDialog();
|
||||
|
||||
this.ProgressBar.RightToLeft = this.RightToLeft;
|
||||
this.ProgressBar.RightToLeftLayout = this.RightToLeftLayout;
|
||||
}
|
||||
|
||||
private void ButtonCancel_MouseEnter(object sender, EventArgs e)
|
||||
|
@ -21,8 +21,10 @@ namespace Bloxstrap.UI.ViewModels.Dialogs
|
||||
|
||||
private void SetLocale()
|
||||
{
|
||||
App.Settings.Prop.Locale = Locale.GetIdentifierFromName(SelectedLanguage);
|
||||
Locale.Set();
|
||||
string identifier = Locale.GetIdentifierFromName(SelectedLanguage);
|
||||
|
||||
Locale.Set(identifier);
|
||||
App.Settings.Prop.Locale = identifier;
|
||||
|
||||
CloseRequestEvent?.Invoke(this, new());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user