diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-06-04 16:22:15 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-06-04 16:22:15 -0400 |
commit | 36930ffd7d363d6afd7f8cac4918c7d1c1c3e339 (patch) | |
tree | 44c3bcc8bedf718c24ae92dd5c9094a398d5e630 /src | |
parent | f8718e044bae89a96431c19e3f3dc11637bad426 (diff) | |
parent | fd485abe28632eda50765f1113ab9f3f453589aa (diff) | |
download | SMAPI-36930ffd7d363d6afd7f8cac4918c7d1c1c3e339.tar.gz SMAPI-36930ffd7d363d6afd7f8cac4918c7d1c1c3e339.tar.bz2 SMAPI-36930ffd7d363d6afd7f8cac4918c7d1c1c3e339.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src')
-rw-r--r-- | src/GlobalAssemblyInfo.cs | 4 | ||||
-rw-r--r-- | src/StardewModdingAPI.Tests/TranslationTests.cs | 64 | ||||
-rw-r--r-- | src/StardewModdingAPI/Constants.cs | 2 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/TranslationHelper.cs | 15 | ||||
-rw-r--r-- | src/StardewModdingAPI/ITranslationHelper.cs | 2 | ||||
-rw-r--r-- | src/StardewModdingAPI/Translation.cs | 10 | ||||
-rw-r--r-- | src/TrainerMod/manifest.json | 2 |
7 files changed, 56 insertions, 43 deletions
diff --git a/src/GlobalAssemblyInfo.cs b/src/GlobalAssemblyInfo.cs index 4344dbce..cb174d48 100644 --- a/src/GlobalAssemblyInfo.cs +++ b/src/GlobalAssemblyInfo.cs @@ -2,5 +2,5 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] -[assembly: AssemblyVersion("1.14.0.0")] -[assembly: AssemblyFileVersion("1.14.0.0")]
\ No newline at end of file +[assembly: AssemblyVersion("1.14.1.0")] +[assembly: AssemblyFileVersion("1.14.1.0")]
\ No newline at end of file diff --git a/src/StardewModdingAPI.Tests/TranslationTests.cs b/src/StardewModdingAPI.Tests/TranslationTests.cs index 6a430aa7..157a08a2 100644 --- a/src/StardewModdingAPI.Tests/TranslationTests.cs +++ b/src/StardewModdingAPI.Tests/TranslationTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using NUnit.Framework; using StardewModdingAPI.Framework; using StardewValley; @@ -32,12 +33,13 @@ namespace StardewModdingAPI.Tests // act ITranslationHelper helper = new TranslationHelper("ModName", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data); Translation translation = helper.Get("key"); + Translation[] translationList = helper.GetTranslations()?.ToArray(); // assert Assert.AreEqual("en", helper.Locale, "The locale doesn't match the input value."); Assert.AreEqual(LocalizedContentManager.LanguageCode.en, helper.LocaleEnum, "The locale enum doesn't match the input value."); - Assert.IsNotNull(helper.GetTranslations(), "The full list of translations is unexpectedly null."); - Assert.AreEqual(0, helper.GetTranslations().Count, "The full list of translations is unexpectedly not empty."); + Assert.IsNotNull(translationList, "The full list of translations is unexpectedly null."); + Assert.AreEqual(0, translationList.Length, "The full list of translations is unexpectedly not empty."); Assert.IsNotNull(translation, "The translation helper unexpectedly returned a null translation."); Assert.AreEqual(this.GetPlaceholderText("key"), translation.ToString(), "The translation returned an unexpected value."); @@ -51,19 +53,19 @@ namespace StardewModdingAPI.Tests var expected = this.GetExpectedTranslations(); // act - var actual = new Dictionary<string, IDictionary<string, string>>(); + var actual = new Dictionary<string, Translation[]>(); TranslationHelper helper = new TranslationHelper("ModName", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data); foreach (string locale in expected.Keys) { this.AssertSetLocale(helper, locale, LocalizedContentManager.LanguageCode.en); - actual[locale] = helper.GetTranslations(); + actual[locale] = helper.GetTranslations()?.ToArray(); } // assert foreach (string locale in expected.Keys) { Assert.IsNotNull(actual[locale], $"The translations for {locale} is unexpectedly null."); - Assert.That(actual[locale], Is.EquivalentTo(expected[locale]), $"The translations for {locale} don't match the expected values."); + Assert.That(actual[locale], Is.EquivalentTo(expected[locale]).Using<Translation, Translation>(this.CompareEquality), $"The translations for {locale} don't match the expected values."); } } @@ -75,21 +77,23 @@ namespace StardewModdingAPI.Tests var expected = this.GetExpectedTranslations(); // act - var actual = new Dictionary<string, IDictionary<string, string>>(); + var actual = new Dictionary<string, Translation[]>(); TranslationHelper helper = new TranslationHelper("ModName", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data); foreach (string locale in expected.Keys) { this.AssertSetLocale(helper, locale, LocalizedContentManager.LanguageCode.en); - actual[locale] = new Dictionary<string, string>(); - foreach (string key in expected[locale].Keys) - actual[locale][key] = helper.Get(key); + + List<Translation> translations = new List<Translation>(); + foreach (Translation translation in expected[locale]) + translations.Add(helper.Get(translation.Key)); + actual[locale] = translations.ToArray(); } // assert foreach (string locale in expected.Keys) { Assert.IsNotNull(actual[locale], $"The translations for {locale} is unexpectedly null."); - Assert.That(actual[locale], Is.EquivalentTo(expected[locale]), $"The translations for {locale} don't match the expected values."); + Assert.That(actual[locale], Is.EquivalentTo(expected[locale]).Using<Translation, Translation>(this.CompareEquality), $"The translations for {locale} don't match the expected values."); } } @@ -292,33 +296,37 @@ namespace StardewModdingAPI.Tests } /// <summary>Get the expected translation output given <see cref="TranslationTests.GetSampleData"/>, based on the expected locale fallback.</summary> - private IDictionary<string, IDictionary<string, string>> GetExpectedTranslations() + private IDictionary<string, Translation[]> GetExpectedTranslations() { - return new Dictionary<string, IDictionary<string, string>> + var expected = new Dictionary<string, Translation[]> { - ["default"] = new Dictionary<string, string> + ["default"] = new[] { - ["key A"] = "default A", - ["key C"] = "default C" + new Translation(string.Empty, "default", "key A", "default A"), + new Translation(string.Empty, "default", "key C", "default C") }, - ["en"] = new Dictionary<string, string> + ["en"] = new[] { - ["key A"] = "en A", - ["key B"] = "en B", - ["key C"] = "default C" + new Translation(string.Empty, "en", "key A", "en A"), + new Translation(string.Empty, "en", "key B", "en B"), + new Translation(string.Empty, "en", "key C", "default C") }, - ["en-us"] = new Dictionary<string, string> + ["zzz"] = new[] { - ["key A"] = "en A", - ["key B"] = "en B", - ["key C"] = "default C" - }, - ["zzz"] = new Dictionary<string, string> - { - ["key A"] = "zzz A", - ["key C"] = "default C" + new Translation(string.Empty, "zzz", "key A", "zzz A"), + new Translation(string.Empty, "zzz", "key C", "default C") } }; + expected["en-us"] = expected["en"].ToArray(); + return expected; + } + + /// <summary>Get whether two translations have the same public values.</summary> + /// <param name="a">The first translation to compare.</param> + /// <param name="b">The second translation to compare.</param> + private bool CompareEquality(Translation a, Translation b) + { + return a.Key == b.Key && a.ToString() == b.ToString(); } /// <summary>Get the default placeholder text when a translation is missing.</summary> diff --git a/src/StardewModdingAPI/Constants.cs b/src/StardewModdingAPI/Constants.cs index 4e53387e..bd489b29 100644 --- a/src/StardewModdingAPI/Constants.cs +++ b/src/StardewModdingAPI/Constants.cs @@ -33,7 +33,7 @@ namespace StardewModdingAPI ** Public ****/ /// <summary>SMAPI's current semantic version.</summary> - public static ISemanticVersion ApiVersion { get; } = new SemanticVersion(1, 14, 0); // alpha-{DateTime.UtcNow:yyyyMMddHHmm} + public static ISemanticVersion ApiVersion { get; } = new SemanticVersion(1, 14, 1); // alpha-{DateTime.UtcNow:yyyyMMddHHmm} /// <summary>The minimum supported version of Stardew Valley.</summary> public static ISemanticVersion MinimumGameVersion { get; } = new SemanticVersion("1.2.30"); 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<string, IDictionary<string, string>> All = new Dictionary<string, IDictionary<string, string>>(StringComparer.InvariantCultureIgnoreCase); /// <summary>The translations for the current locale, with locale fallback taken into account.</summary> - private IDictionary<string, string> ForLocale; + private IDictionary<string, Translation> ForLocale; /********* @@ -47,17 +48,17 @@ namespace StardewModdingAPI.Framework } /// <summary>Get all translations for the current locale.</summary> - public IDictionary<string, string> GetTranslations() + public IEnumerable<Translation> GetTranslations() { - return new Dictionary<string, string>(this.ForLocale, StringComparer.InvariantCultureIgnoreCase); + return this.ForLocale.Values.ToArray(); } /// <summary>Get a translation for the current locale.</summary> /// <param name="key">The translation key.</param> 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); } /// <summary>Get a translation for the current locale.</summary> @@ -91,7 +92,7 @@ namespace StardewModdingAPI.Framework this.Locale = locale.ToLower().Trim(); this.LocaleEnum = localeEnum; - this.ForLocale = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase); + this.ForLocale = new Dictionary<string, Translation>(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)); } } } diff --git a/src/StardewModdingAPI/ITranslationHelper.cs b/src/StardewModdingAPI/ITranslationHelper.cs index 15f6b3c8..dac83025 100644 --- a/src/StardewModdingAPI/ITranslationHelper.cs +++ b/src/StardewModdingAPI/ITranslationHelper.cs @@ -20,7 +20,7 @@ namespace StardewModdingAPI ** Public methods *********/ /// <summary>Get all translations for the current locale.</summary> - IDictionary<string, string> GetTranslations(); + IEnumerable<Translation> GetTranslations(); /// <summary>Get a translation for the current locale.</summary> /// <param name="key">The translation key.</param> diff --git a/src/StardewModdingAPI/Translation.cs b/src/StardewModdingAPI/Translation.cs index 764145ea..ce344f81 100644 --- a/src/StardewModdingAPI/Translation.cs +++ b/src/StardewModdingAPI/Translation.cs @@ -21,9 +21,6 @@ namespace StardewModdingAPI /// <summary>The locale for which the translation was fetched.</summary> private readonly string Locale; - /// <summary>The translation key.</summary> - private readonly string Key; - /// <summary>The underlying translation text.</summary> private readonly string Text; @@ -32,6 +29,13 @@ namespace StardewModdingAPI /********* + ** Accessors + *********/ + /// <summary>The original translation key.</summary> + public string Key { get; } + + + /********* ** Public methods *********/ /// <summary>Construct an isntance.</summary> diff --git a/src/TrainerMod/manifest.json b/src/TrainerMod/manifest.json index 1232a365..40eb3237 100644 --- a/src/TrainerMod/manifest.json +++ b/src/TrainerMod/manifest.json @@ -4,7 +4,7 @@ "Version": { "MajorVersion": 1, "MinorVersion": 14, - "PatchVersion": 0, + "PatchVersion": 1, "Build": null }, "Description": "Adds SMAPI console commands that let you manipulate the game.", |