summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI/Program.cs20
2 files changed, 20 insertions, 1 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index f6498f06..b5d6e32a 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -14,6 +14,7 @@
* Added `SpecialisedEvents.UnvalidatedUpdateTick` event for specialised use cases.
* Fixed deadlock in rare cases when injecting a file with an asset loader.
* Fixed unhelpful error when a mod exposes a non-public API.
+ * Fixed unhelpful error when a translation file has duplicate keys due to case-insensitivity.
* Fixed input events being raised for keyboard buttons when a textbox is receiving input.
* Fixed some JSON field names being case-sensitive.
* Fixed `helper.ReadJsonFile` and `helper.WriteJsonFile` not normalising path separators.
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs
index aecf5b30..e9084b2d 100644
--- a/src/SMAPI/Program.cs
+++ b/src/SMAPI/Program.cs
@@ -765,7 +765,7 @@ namespace StardewModdingAPI
IContentHelper packContentHelper = new ContentHelper(contentManager, packDirPath, packManifest.UniqueID, packManifest.Name, packMonitor);
return new ContentPack(packDirPath, packManifest, packContentHelper, this.JsonHelper);
}
-
+
modHelper = new ModHelper(manifest.UniqueID, metadata.DirectoryPath, jsonHelper, contentHelper, commandHelper, modRegistryHelper, reflectionHelper, translationHelper, contentPacks, CreateTransitionalContentPack, this.DeprecationManager);
}
@@ -993,6 +993,24 @@ namespace StardewModdingAPI
}
}
+ // validate translations
+ foreach (string locale in translations.Keys)
+ {
+ HashSet<string> keys = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
+ HashSet<string> duplicateKeys = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
+ foreach (string key in translations[locale].Keys.ToArray())
+ {
+ if (!keys.Add(key))
+ {
+ duplicateKeys.Add(key);
+ 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);
+ }
+
// update translation
TranslationHelper translationHelper = (TranslationHelper)metadata.Mod.Helper.Translation;
translationHelper.SetTranslations(translations);