mirror of
https://github.com/GreemDev/Ryujinx.git
synced 2025-01-09 14:41:59 +00:00
Improve locale file parsing error descriptions
This commit is contained in:
parent
0ca4d6e921
commit
0bacdb8765
1 changed files with 12 additions and 6 deletions
|
@ -143,11 +143,7 @@ namespace Ryujinx.Ava.Common.Locale
|
||||||
LocaleChanged?.Invoke();
|
LocaleChanged?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
#nullable enable
|
|
||||||
|
|
||||||
private static LocalesJson? _localeData;
|
private static LocalesJson? _localeData;
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
private static Dictionary<LocaleKeys, string> LoadJsonLanguage(string languageCode)
|
private static Dictionary<LocaleKeys, string> LoadJsonLanguage(string languageCode)
|
||||||
{
|
{
|
||||||
|
@ -158,18 +154,28 @@ namespace Ryujinx.Ava.Common.Locale
|
||||||
|
|
||||||
foreach (LocalesEntry locale in _localeData.Value.Locales)
|
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}!");
|
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))
|
if (!Enum.TryParse<LocaleKeys>(locale.ID, out var localeKey))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
localeStrings[localeKey] =
|
localeStrings[localeKey] =
|
||||||
locale.Translations.TryGetValue(languageCode, out string val) && val != string.Empty
|
locale.Translations.TryGetValue(languageCode, out string val) && !string.IsNullOrEmpty(val)
|
||||||
? val
|
? val
|
||||||
: locale.Translations[DefaultLanguageCode];
|
: 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;
|
return localeStrings;
|
||||||
|
|
Loading…
Reference in a new issue