From 91cec58fdbd699380aa2714acf1c1981ccde7dff Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 3 Jun 2017 23:56:43 -0400 Subject: tweak translation API to always return translations (#303) --- src/StardewModdingAPI/Framework/TranslationHelper.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/StardewModdingAPI/Framework') diff --git a/src/StardewModdingAPI/Framework/TranslationHelper.cs b/src/StardewModdingAPI/Framework/TranslationHelper.cs index 1e73c425..fe387789 100644 --- a/src/StardewModdingAPI/Framework/TranslationHelper.cs +++ b/src/StardewModdingAPI/Framework/TranslationHelper.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using StardewValley; namespace StardewModdingAPI.Framework @@ -17,7 +18,7 @@ namespace StardewModdingAPI.Framework private readonly IDictionary> All = new Dictionary>(StringComparer.InvariantCultureIgnoreCase); /// The translations for the current locale, with locale fallback taken into account. - private IDictionary ForLocale; + private IDictionary ForLocale; /********* @@ -47,17 +48,17 @@ namespace StardewModdingAPI.Framework } /// Get all translations for the current locale. - public IDictionary GetTranslations() + public IEnumerable GetTranslations() { - return new Dictionary(this.ForLocale, StringComparer.InvariantCultureIgnoreCase); + return this.ForLocale.Values.ToArray(); } /// Get a translation for the current locale. /// The translation key. public Translation Get(string key) { - this.ForLocale.TryGetValue(key, out string text); - return new Translation(this.ModName, this.Locale, key, text); + this.ForLocale.TryGetValue(key, out Translation translation); + return translation ?? new Translation(this.ModName, this.Locale, key, null); } /// Get a translation for the current locale. @@ -91,7 +92,7 @@ namespace StardewModdingAPI.Framework this.Locale = locale.ToLower().Trim(); this.LocaleEnum = localeEnum; - this.ForLocale = new Dictionary(StringComparer.InvariantCultureIgnoreCase); + this.ForLocale = new Dictionary(StringComparer.InvariantCultureIgnoreCase); foreach (string next in this.GetRelevantLocales(this.Locale)) { // skip if locale not defined @@ -102,7 +103,7 @@ namespace StardewModdingAPI.Framework foreach (var pair in translations) { if (!this.ForLocale.ContainsKey(pair.Key)) - this.ForLocale.Add(pair); + this.ForLocale.Add(pair.Key, new Translation(this.ModName, this.Locale, pair.Key, pair.Value)); } } } -- cgit