fix error reading empty translation files
This commit is contained in:
parent
1fd52f8b63
commit
edb44cdb40
|
@ -53,6 +53,7 @@
|
|||
* Fixed assets loaded by temporary content managers not being editable by mods.
|
||||
* Fixed assets not reloaded consistently when the player switches language.
|
||||
* Fixed error if a mod loads a PNG while the game is loading (e.g. custom map tilesheets via `IAssetLoader`).
|
||||
* Fixed error if a mod translation file is empty.
|
||||
* Fixed input suppression not working consistently for clicks.
|
||||
* Fixed console command input not saved to the log.
|
||||
* Fixed `Context.IsPlayerFree` being false during festivals.
|
||||
|
|
|
@ -1143,8 +1143,17 @@ namespace StardewModdingAPI
|
|||
}
|
||||
|
||||
// validate translations
|
||||
foreach (string locale in translations.Keys)
|
||||
foreach (string locale in translations.Keys.ToArray())
|
||||
{
|
||||
// skip empty files
|
||||
if (translations[locale] == null || !translations[locale].Keys.Any())
|
||||
{
|
||||
metadata.LogAsMod($"Mod's i18n/{locale}.json is empty and will be ignored.", LogLevel.Warn);
|
||||
translations.Remove(locale);
|
||||
continue;
|
||||
}
|
||||
|
||||
// handle duplicates
|
||||
HashSet<string> keys = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
|
||||
HashSet<string> duplicateKeys = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
|
||||
foreach (string key in translations[locale].Keys.ToArray())
|
||||
|
@ -1155,7 +1164,6 @@ namespace StardewModdingAPI
|
|||
translations[locale].Remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
if (duplicateKeys.Any())
|
||||
metadata.LogAsMod($"Mod's i18n/{locale}.json has duplicate translation keys: [{string.Join(", ", duplicateKeys)}]. Keys are case-insensitive.", LogLevel.Warn);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue