summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-05-28 01:49:21 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-05-28 01:49:21 -0400
commit5af58c7b18a120ce47f230ede7f116678d97e038 (patch)
tree0639add41b5e6b9e234d8e2c17884fd0153c76b9 /src/StardewModdingAPI/Framework
parent12ffd9c334906e2256a1c32976b6a07f75027f25 (diff)
downloadSMAPI-5af58c7b18a120ce47f230ede7f116678d97e038.tar.gz
SMAPI-5af58c7b18a120ce47f230ede7f116678d97e038.tar.bz2
SMAPI-5af58c7b18a120ce47f230ede7f116678d97e038.zip
refactor translation init for reuse (#296)
Diffstat (limited to 'src/StardewModdingAPI/Framework')
-rw-r--r--src/StardewModdingAPI/Framework/ModHelper.cs5
-rw-r--r--src/StardewModdingAPI/Framework/TranslationHelper.cs20
2 files changed, 18 insertions, 7 deletions
diff --git a/src/StardewModdingAPI/Framework/ModHelper.cs b/src/StardewModdingAPI/Framework/ModHelper.cs
index 8c578dbe..947b1ae8 100644
--- a/src/StardewModdingAPI/Framework/ModHelper.cs
+++ b/src/StardewModdingAPI/Framework/ModHelper.cs
@@ -47,10 +47,9 @@ namespace StardewModdingAPI.Framework
/// <param name="commandManager">Manages console commands.</param>
/// <param name="contentManager">The content manager which loads content assets.</param>
/// <param name="reflection">Simplifies access to private game code.</param>
- /// <param name="translations">Provides translations stored in the mod folder.</param>
/// <exception cref="ArgumentNullException">An argument is null or empty.</exception>
/// <exception cref="InvalidOperationException">The <paramref name="modDirectory"/> path does not exist on disk.</exception>
- public ModHelper(string displayName, string modDirectory, JsonHelper jsonHelper, IModRegistry modRegistry, CommandManager commandManager, SContentManager contentManager, IReflectionHelper reflection, ITranslationHelper translations)
+ public ModHelper(string displayName, string modDirectory, JsonHelper jsonHelper, IModRegistry modRegistry, CommandManager commandManager, SContentManager contentManager, IReflectionHelper reflection)
{
// validate
if (string.IsNullOrWhiteSpace(modDirectory))
@@ -69,7 +68,7 @@ namespace StardewModdingAPI.Framework
this.ModRegistry = modRegistry;
this.ConsoleCommands = new CommandHelper(displayName, commandManager);
this.Reflection = reflection;
- this.Translation = translations;
+ this.Translation = new TranslationHelper(displayName, contentManager.GetLocale(), contentManager.GetCurrentLanguage());
}
/****
diff --git a/src/StardewModdingAPI/Framework/TranslationHelper.cs b/src/StardewModdingAPI/Framework/TranslationHelper.cs
index c3104d1b..ebcd69b1 100644
--- a/src/StardewModdingAPI/Framework/TranslationHelper.cs
+++ b/src/StardewModdingAPI/Framework/TranslationHelper.cs
@@ -41,13 +41,10 @@ namespace StardewModdingAPI.Framework
/// <param name="modName">The name of the relevant mod for error messages.</param>
/// <param name="locale">The initial locale.</param>
/// <param name="languageCode">The game's current language code.</param>
- /// <param name="translations">The translations for each locale.</param>
- public TranslationHelper(string modName, string locale, LocalizedContentManager.LanguageCode languageCode, IDictionary<string, IDictionary<string, string>> translations)
+ public TranslationHelper(string modName, string locale, LocalizedContentManager.LanguageCode languageCode)
{
// save data
this.ModName = modName;
- foreach (var pair in translations)
- this.All[pair.Key] = new Dictionary<string, string>(pair.Value, StringComparer.InvariantCultureIgnoreCase);
// set locale
this.SetLocale(locale, languageCode);
@@ -67,6 +64,21 @@ namespace StardewModdingAPI.Framework
return new Translation(this.ModName, this.Locale, key, text);
}
+ /// <summary>Set the translations to use.</summary>
+ /// <param name="translations">The translations to use.</param>
+ internal TranslationHelper SetTranslations(IDictionary<string, IDictionary<string, string>> translations)
+ {
+ // reset translations
+ this.All.Clear();
+ foreach (var pair in translations)
+ this.All[pair.Key] = new Dictionary<string, string>(pair.Value, StringComparer.InvariantCultureIgnoreCase);
+
+ // rebuild cache
+ this.SetLocale(this.Locale, this.LocaleEnum);
+
+ return this;
+ }
+
/// <summary>Set the current locale and precache translations.</summary>
/// <param name="locale">The current locale.</param>
/// <param name="localeEnum">The game's current language code.</param>