From 0bacdb8765988d2d9aff3a859d9c6cb64cc5e142 Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Tue, 24 Dec 2024 22:19:58 -0600 Subject: [PATCH] Improve locale file parsing error descriptions --- src/Ryujinx/Common/LocaleManager.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Ryujinx/Common/LocaleManager.cs b/src/Ryujinx/Common/LocaleManager.cs index 270b666df..e788a3adc 100644 --- a/src/Ryujinx/Common/LocaleManager.cs +++ b/src/Ryujinx/Common/LocaleManager.cs @@ -143,11 +143,7 @@ namespace Ryujinx.Ava.Common.Locale LocaleChanged?.Invoke(); } - #nullable enable - private static LocalesJson? _localeData; - - #nullable disable private static Dictionary LoadJsonLanguage(string languageCode) { @@ -158,18 +154,28 @@ namespace Ryujinx.Ava.Common.Locale foreach (LocalesEntry locale in _localeData.Value.Locales) { - if (locale.Translations.Count != _localeData.Value.Languages.Count) + if (locale.Translations.Count < _localeData.Value.Languages.Count) { throw new Exception($"Locale key {{{locale.ID}}} is missing languages! Has {locale.Translations.Count} translations, expected {_localeData.Value.Languages.Count}!"); + } + + if (locale.Translations.Count > _localeData.Value.Languages.Count) + { + throw new Exception($"Locale key {{{locale.ID}}} has too many languages! Has {locale.Translations.Count} translations, expected {_localeData.Value.Languages.Count}!"); } if (!Enum.TryParse(locale.ID, out var localeKey)) continue; localeStrings[localeKey] = - locale.Translations.TryGetValue(languageCode, out string val) && val != string.Empty + locale.Translations.TryGetValue(languageCode, out string val) && !string.IsNullOrEmpty(val) ? val : locale.Translations[DefaultLanguageCode]; + + if (string.IsNullOrEmpty(localeStrings[localeKey])) + { + throw new Exception($"Locale key '{locale.ID}' has no valid translations for desired language {languageCode}! {DefaultLanguageCode} is an empty string or null"); + } } return localeStrings;