aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIsaac Marovitz <42140194+IsaacMarovitz@users.noreply.github.com>2024-03-17 01:27:14 +0000
committerGitHub <noreply@github.com>2024-03-17 02:27:14 +0100
commita0552fd78ba90c843e8af6c7dd040f1fc83d72e9 (patch)
treee87a9b188621ee9185c5868c4f33c373fd8ca5bb /src
parentbb8c5ebae1cc9666cccd83106f592148e7aa4293 (diff)
Ava UI: Fix locale crash (#6385)1.1.1238
* Fix locale crash * Apply suggestions from code review --------- Co-authored-by: Ac_K <Acoustik666@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/Ryujinx/Common/Locale/LocaleManager.cs54
1 files changed, 33 insertions, 21 deletions
diff --git a/src/Ryujinx/Common/Locale/LocaleManager.cs b/src/Ryujinx/Common/Locale/LocaleManager.cs
index e973fcc0..2d3deeaa 100644
--- a/src/Ryujinx/Common/Locale/LocaleManager.cs
+++ b/src/Ryujinx/Common/Locale/LocaleManager.cs
@@ -30,28 +30,22 @@ namespace Ryujinx.Ava.Common.Locale
Load();
}
- public void Load()
+ private void Load()
{
- // Load the system Language Code.
- string localeLanguageCode = CultureInfo.CurrentCulture.Name.Replace('-', '_');
+ var localeLanguageCode = !string.IsNullOrEmpty(ConfigurationState.Instance.UI.LanguageCode.Value) ?
+ ConfigurationState.Instance.UI.LanguageCode.Value : CultureInfo.CurrentCulture.Name.Replace('-', '_');
- // If the view is loaded with the UI Previewer detached, then override it with the saved one or default.
+ // Load en_US as default, if the target language translation is missing or incomplete.
+ LoadDefaultLanguage();
+ LoadLanguage(localeLanguageCode);
+
+ // Save whatever we ended up with.
if (Program.PreviewerDetached)
{
- if (!string.IsNullOrEmpty(ConfigurationState.Instance.UI.LanguageCode.Value))
- {
- localeLanguageCode = ConfigurationState.Instance.UI.LanguageCode.Value;
- }
- else
- {
- localeLanguageCode = DefaultLanguageCode;
- }
- }
+ ConfigurationState.Instance.UI.LanguageCode.Value = _localeLanguageCode;
- // Load en_US as default, if the target language translation is incomplete.
- LoadDefaultLanguage();
-
- LoadLanguage(localeLanguageCode);
+ ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
+ }
}
public string this[LocaleKeys key]
@@ -126,24 +120,42 @@ namespace Ryujinx.Ava.Common.Locale
private void LoadDefaultLanguage()
{
- _localeDefaultStrings = LoadJsonLanguage();
+ _localeDefaultStrings = LoadJsonLanguage(DefaultLanguageCode);
}
public void LoadLanguage(string languageCode)
{
- foreach (var item in LoadJsonLanguage(languageCode))
+ var locale = LoadJsonLanguage(languageCode);
+
+ if (locale == null)
+ {
+ _localeLanguageCode = DefaultLanguageCode;
+ locale = _localeDefaultStrings;
+ }
+ else
+ {
+ _localeLanguageCode = languageCode;
+ }
+
+ foreach (var item in locale)
{
this[item.Key] = item.Value;
}
- _localeLanguageCode = languageCode;
LocaleChanged?.Invoke();
}
- private static Dictionary<LocaleKeys, string> LoadJsonLanguage(string languageCode = DefaultLanguageCode)
+ private static Dictionary<LocaleKeys, string> LoadJsonLanguage(string languageCode)
{
var localeStrings = new Dictionary<LocaleKeys, string>();
string languageJson = EmbeddedResources.ReadAllText($"Ryujinx/Assets/Locales/{languageCode}.json");
+
+ if (languageJson == null)
+ {
+ // We were unable to find file for that language code.
+ return null;
+ }
+
var strings = JsonHelper.Deserialize(languageJson, CommonJsonContext.Default.StringDictionary);
foreach (var item in strings)