summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-07-09 20:59:39 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-07-09 20:59:39 -0400
commitedb44cdb4011b794e45bc278c55e41af98ebf06b (patch)
treeaabb96e1a901ca57390d91074046c9bc8107defe
parent1fd52f8b63d2369de84b7ab8d54596d2cb597abf (diff)
downloadSMAPI-edb44cdb4011b794e45bc278c55e41af98ebf06b.tar.gz
SMAPI-edb44cdb4011b794e45bc278c55e41af98ebf06b.tar.bz2
SMAPI-edb44cdb4011b794e45bc278c55e41af98ebf06b.zip
fix error reading empty translation files
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI/Program.cs12
2 files changed, 11 insertions, 2 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index bbf04556..0fd6801e 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -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.
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs
index c9266c69..24bf0d59 100644
--- a/src/SMAPI/Program.cs
+++ b/src/SMAPI/Program.cs
@@ -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);
}