From 1f24670be8872cdf5f2c1a039bc8ac0b941daef0 Mon Sep 17 00:00:00 2001 From: Chance Millar Date: Tue, 7 May 2024 22:54:12 +0100 Subject: [PATCH] Implemented temporary fallback for unsupported languages. (#87) --- src/G2DataGUI.UI.Common/Locale/LocaleManager.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/G2DataGUI.UI.Common/Locale/LocaleManager.cs b/src/G2DataGUI.UI.Common/Locale/LocaleManager.cs index 5221b0c..b7d31eb 100644 --- a/src/G2DataGUI.UI.Common/Locale/LocaleManager.cs +++ b/src/G2DataGUI.UI.Common/Locale/LocaleManager.cs @@ -23,7 +23,7 @@ private LocaleManager() public void Load() { - string systemLanguageCode = CultureInfo.CurrentCulture.Name.Replace("-", "_"); + string systemLanguageCode = GetSupportedLanguage(); LoadLanguage(systemLanguageCode); LoadDefaultLanguage(); } @@ -36,9 +36,17 @@ public void LoadLanguage(string languageCode) } } - private void LoadDefaultLanguage() => _defaultLocaleStringLists = LoadJsonLanguage(); + private void LoadDefaultLanguage() => _defaultLocaleStringLists = LoadJsonLanguage(); - private Dictionary> LoadJsonLanguage(string languageCode = DefaultLanguageCode) + private string GetSupportedLanguage() + { + string systemLanguage = CultureInfo.CurrentCulture.Name.Replace("-", "_"); + + // Todo: Check if systemLanguage is in supported locales, at the moment it's only en_US. + return DefaultLanguageCode; + } + + private Dictionary> LoadJsonLanguage(string languageCode = DefaultLanguageCode) { Dictionary> localeStringLists = new(); string jsonData = EmbeddedResources.ReadAllText($"G2DataGUI.UI.Common/Assets/Locales/{languageCode}.json");