summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-02-22 20:26:21 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-02-22 20:26:21 -0500
commitddba317142b6b5cbf3efbc867d0b5bd95afcefb2 (patch)
tree818627a691257159d93b7c838dbf0ebc0bb45200
parentec1e5a169828d95c6cf0c779089b25627754c894 (diff)
downloadSMAPI-ddba317142b6b5cbf3efbc867d0b5bd95afcefb2.tar.gz
SMAPI-ddba317142b6b5cbf3efbc867d0b5bd95afcefb2.tar.bz2
SMAPI-ddba317142b6b5cbf3efbc867d0b5bd95afcefb2.zip
add friendly warning when an i18n file has duplicate keys due to case-insensitivity (#448)
-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);