mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-20 09:31:29 -07:00
this is a draft as i can't fully test this right now because i'm currently 37000 feet in the air and a 75 MB data quota costs 10 bucks :( this also may be the first documented instance of me using wpf 100% properly as bill gates himself intended
81 lines
2.6 KiB
C#
81 lines
2.6 KiB
C#
using System;
|
|
using System.Windows;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Bloxstrap.Resources;
|
|
|
|
namespace Bloxstrap
|
|
{
|
|
internal static class Locale
|
|
{
|
|
// TODO: put translated names
|
|
public static readonly Dictionary<string, string> SupportedLocales = new()
|
|
{
|
|
{ "nil", Strings.Enums_Theme_Default }, // /shrug
|
|
{ "en", "English" },
|
|
{ "en-US", "English (United States)" },
|
|
{ "ar", "Arabic" },
|
|
{ "bn", "Bengali" },
|
|
{ "bs", "Bosnian" },
|
|
{ "bg", "Bulgarian" },
|
|
{ "zh-CN", "Chinese (Simplified)" },
|
|
{ "zh-TW", "Chinese (Traditional)" },
|
|
{ "cs", "Czech" },
|
|
{ "dk", "Danish" },
|
|
{ "nl", "Dutch" },
|
|
{ "fl", "Filipino" },
|
|
{ "fi", "Finnish" },
|
|
{ "fr", "French" },
|
|
{ "de", "German" },
|
|
{ "he", "Hebrew" },
|
|
{ "hi", "Hindi" },
|
|
{ "hu", "Hungarian" },
|
|
{ "id", "Indonesian" },
|
|
{ "it", "Italian" },
|
|
{ "ja", "Japanese" },
|
|
{ "ko", "Korean" },
|
|
{ "lt", "Lithuanian" },
|
|
{ "no", "Norwegian" },
|
|
{ "pl", "Polish" },
|
|
{ "pt-BR", "Portuguese" },
|
|
{ "ro", "Romanian" },
|
|
{ "ru", "Russian" },
|
|
{ "es", "Spanish" },
|
|
{ "sv-SE", "Swedish" },
|
|
{ "th", "Thai" },
|
|
{ "tr", "Turkish" },
|
|
{ "uk", "Ukrainian" },
|
|
{ "vi", "Vietnamese" }
|
|
};
|
|
|
|
public static string GetIdentifierFromName(string language) => Locale.SupportedLocales.Where(x => x.Value == language).First().Key;
|
|
|
|
public static void Set()
|
|
{
|
|
string identifier = App.Settings.Prop.Locale;
|
|
|
|
if (!SupportedLocales.ContainsKey(identifier))
|
|
identifier = "nil";
|
|
|
|
if (identifier == "nil")
|
|
return;
|
|
|
|
App.CurrentCulture = new CultureInfo(identifier);
|
|
|
|
CultureInfo.DefaultThreadCurrentUICulture = App.CurrentCulture;
|
|
Thread.CurrentThread.CurrentUICulture = App.CurrentCulture;
|
|
|
|
if (identifier == "ar" || identifier == "he")
|
|
{
|
|
// TODO: credit the SO post i took this from
|
|
EventManager.RegisterClassHandler(typeof(Window), FrameworkElement.LoadedEvent, new RoutedEventHandler((window, _) =>
|
|
{
|
|
((Window)window).FlowDirection = FlowDirection.RightToLeft;
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
}
|