Skip to content

Commit

Permalink
Improve locale file parsing error descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
GreemDev committed Dec 25, 2024
1 parent 0ca4d6e commit 0bacdb8
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Ryujinx/Common/LocaleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,7 @@ public void LoadLanguage(string languageCode)
LocaleChanged?.Invoke();
}

#nullable enable

private static LocalesJson? _localeData;

#nullable disable

private static Dictionary<LocaleKeys, string> LoadJsonLanguage(string languageCode)
{
Expand All @@ -158,18 +154,28 @@ private static Dictionary<LocaleKeys, string> LoadJsonLanguage(string languageCo

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<LocaleKeys>(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;
Expand Down

0 comments on commit 0bacdb8

Please sign in to comment.