Move locale info, fix RTL layout in context menus

This commit is contained in:
pizzaboxer 2024-06-29 11:47:48 +04:00
parent 8dfd12b7f0
commit 8fd3fd7737
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
3 changed files with 20 additions and 8 deletions

View File

@ -29,8 +29,6 @@ namespace Bloxstrap
public static LaunchSettings LaunchSettings { get; private set; } = null!; public static LaunchSettings LaunchSettings { get; private set; } = null!;
public static CultureInfo CurrentCulture { get; set; } = CultureInfo.InvariantCulture;
public static BuildMetadataAttribute BuildMetadata = Assembly.GetExecutingAssembly().GetCustomAttribute<BuildMetadataAttribute>()!; public static BuildMetadataAttribute BuildMetadata = Assembly.GetExecutingAssembly().GetCustomAttribute<BuildMetadataAttribute>()!;
public static string Version = Assembly.GetExecutingAssembly().GetName().Version!.ToString()[..^2]; public static string Version = Assembly.GetExecutingAssembly().GetName().Version!.ToString()[..^2];
@ -113,7 +111,7 @@ namespace Bloxstrap
{ {
const string LOG_IDENT = "App::OnStartup"; const string LOG_IDENT = "App::OnStartup";
CurrentCulture = Thread.CurrentThread.CurrentUICulture; Locale.CurrentCulture = Thread.CurrentThread.CurrentUICulture;
base.OnStartup(e); base.OnStartup(e);

View File

@ -6,6 +6,8 @@ namespace Bloxstrap
{ {
internal static class Locale internal static class Locale
{ {
public static CultureInfo CurrentCulture = CultureInfo.InvariantCulture;
public static readonly Dictionary<string, string> SupportedLocales = new() public static readonly Dictionary<string, string> SupportedLocales = new()
{ {
{ "nil", Strings.Enums_Theme_Default }, // /shrug { "nil", Strings.Enums_Theme_Default }, // /shrug
@ -72,17 +74,29 @@ namespace Bloxstrap
if (identifier == "nil") if (identifier == "nil")
return; return;
App.CurrentCulture = new CultureInfo(identifier); CurrentCulture = new CultureInfo(identifier);
CultureInfo.DefaultThreadCurrentUICulture = App.CurrentCulture; CultureInfo.DefaultThreadCurrentUICulture = CurrentCulture;
Thread.CurrentThread.CurrentUICulture = App.CurrentCulture; Thread.CurrentThread.CurrentUICulture = CurrentCulture;
RoutedEventHandler? handler = null; RoutedEventHandler? handler = null;
if (identifier == "ar" || identifier == "he") if (identifier == "ar" || identifier == "he")
handler = new((window, _) => ((Window)window).FlowDirection = FlowDirection.RightToLeft); {
handler = new((sender, _) =>
{
var window = (Window)sender;
window.FlowDirection = FlowDirection.RightToLeft;
if (window.ContextMenu is not null)
window.ContextMenu.FlowDirection = FlowDirection.RightToLeft;
});
}
else if (identifier == "th") else if (identifier == "th")
{
handler = new((window, _) => ((Window)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 // 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) if (handler is not null)

View File

@ -97,7 +97,7 @@
WriteLine($"[{identifier}] {ex}"); WriteLine($"[{identifier}] {ex}");
Thread.CurrentThread.CurrentUICulture = App.CurrentCulture; Thread.CurrentThread.CurrentUICulture = Locale.CurrentCulture;
} }
private async void WriteToLog(string message) private async void WriteToLog(string message)