use enum for language names

This commit is contained in:
Jesse Plamondon-Willard 2019-01-05 23:33:45 -05:00
parent 03ca0277da
commit cfe5cdc49e
No known key found for this signature in database
GPG Key ID: 7D7C8097B62033CE
8 changed files with 467 additions and 473 deletions

View File

@ -11,22 +11,19 @@ namespace Vocalization.Framework
public static Dictionary<string, SortedDictionary<string, VoiceAudioOptions>> DictionaryReferences = new Dictionary<string, SortedDictionary<string, VoiceAudioOptions>>(); public static Dictionary<string, SortedDictionary<string, VoiceAudioOptions>> DictionaryReferences = new Dictionary<string, SortedDictionary<string, VoiceAudioOptions>>();
public static string generateKey(string translationPath, string SpeakerName, string fileName, string dialogueKey) public static string generateKey(LanguageName language, string SpeakerName, string fileName, string dialogueKey)
{ {
return Vocalization.config.translationInfo.getTranslationNameFromPath(translationPath) + Seperator + SpeakerName + Seperator + fileName + Seperator + dialogueKey; return Vocalization.config.translationInfo.getTranslationName(language) + Seperator + SpeakerName + Seperator + fileName + Seperator + dialogueKey;
} }
public static SortedDictionary<string, VoiceAudioOptions> getWavFileReferences(string translation) public static SortedDictionary<string, VoiceAudioOptions> getWavFileReferences(LanguageName language)
{ {
return DictionaryReferences[Vocalization.config.translationInfo.getTranslationNameFromPath(translation)]; return DictionaryReferences[Vocalization.config.translationInfo.getTranslationName(language)];
} }
public static void initialize() public static void initialize()
{ {
if (!Directory.Exists(Path.Combine(Vocalization.ModHelper.DirectoryPath, "AudioCues"))) Directory.CreateDirectory(Path.Combine(Vocalization.ModHelper.DirectoryPath, "AudioCues"));
{
Directory.CreateDirectory(Path.Combine(Vocalization.ModHelper.DirectoryPath, "AudioCues"));
}
loadAudioCues(); loadAudioCues();
} }
@ -45,20 +42,19 @@ namespace Vocalization.Framework
public static void loadAudioCues() public static void loadAudioCues()
{ {
foreach (string v in Vocalization.config.translationInfo.LanguageNames) foreach (LanguageName language in Vocalization.config.translationInfo.LanguageNames)
{ {
var loaded = Vocalization.ModHelper.ReadJsonFile<SortedDictionary<string, VoiceAudioOptions>>(Path.Combine(Vocalization.ModHelper.DirectoryPath, "AudioCues", "AudioCues" + Seperator + v + ".json")); var loaded =
if (loaded == null) loaded = new SortedDictionary<string, VoiceAudioOptions>(); Vocalization.ModHelper.ReadJsonFile<SortedDictionary<string, VoiceAudioOptions>>(Path.Combine(Vocalization.ModHelper.DirectoryPath, "AudioCues", "AudioCues" + Seperator + language + ".json"))
DictionaryReferences.Add(v, loaded); ?? new SortedDictionary<string, VoiceAudioOptions>();
DictionaryReferences.Add(Vocalization.config.translationInfo.getTranslationName(language), loaded);
} }
} }
public static void saveAudioCues() public static void saveAudioCues()
{ {
foreach (var v in DictionaryReferences) foreach (var v in DictionaryReferences)
{
Vocalization.ModHelper.WriteJsonFile<SortedDictionary<string, VoiceAudioOptions>>(Path.Combine(Vocalization.ModHelper.DirectoryPath, "AudioCues", "AudioCues" + Seperator + v.Key + ".json"), v.Value); Vocalization.ModHelper.WriteJsonFile<SortedDictionary<string, VoiceAudioOptions>>(Path.Combine(Vocalization.ModHelper.DirectoryPath, "AudioCues", "AudioCues" + Seperator + v.Key + ".json"), v.Value);
}
} }
} }
} }

View File

@ -172,13 +172,16 @@ namespace Vocalization.Framework
} }
/// <summary>Change all of the files to the ones that are appropriate for that translation version.</summary> /// <summary>Change all of the files to the ones that are appropriate for that translation version.</summary>
public void initializeForTranslation(string translation) /// <param name="language">The translation language name.</param>
public void initializeForTranslation(LanguageName language)
{ {
string extension = Vocalization.config.translationInfo.getFileExtentionForTranslation(language);
for (int i = 0; i < this.dataFileNames.Count; i++) for (int i = 0; i < this.dataFileNames.Count; i++)
{ {
Vocalization.ModMonitor.Log(this.dataFileNames.ElementAt(i)); Vocalization.ModMonitor.Log(this.dataFileNames.ElementAt(i));
string s = this.dataFileNames.ElementAt(i); string s = this.dataFileNames.ElementAt(i);
s = this.dataFileNames.ElementAt(i).Replace(".xnb", Vocalization.config.translationInfo.getFileExtentionForTranslation(translation)); s = this.dataFileNames.ElementAt(i).Replace(".xnb", extension);
this.dataFileNames[i] = s; this.dataFileNames[i] = s;
Vocalization.ModMonitor.Log(this.dataFileNames.ElementAt(i)); Vocalization.ModMonitor.Log(this.dataFileNames.ElementAt(i));
} }
@ -187,7 +190,7 @@ namespace Vocalization.Framework
{ {
Vocalization.ModMonitor.Log(this.dialogueFileNames.ElementAt(i)); Vocalization.ModMonitor.Log(this.dialogueFileNames.ElementAt(i));
string s = this.dialogueFileNames.ElementAt(i); string s = this.dialogueFileNames.ElementAt(i);
s = this.dialogueFileNames.ElementAt(i).Replace(".xnb", Vocalization.config.translationInfo.getFileExtentionForTranslation(translation)); s = this.dialogueFileNames.ElementAt(i).Replace(".xnb", extension);
this.dialogueFileNames[i] = s; this.dialogueFileNames[i] = s;
Vocalization.ModMonitor.Log(this.dialogueFileNames.ElementAt(i)); Vocalization.ModMonitor.Log(this.dialogueFileNames.ElementAt(i));
} }
@ -196,7 +199,7 @@ namespace Vocalization.Framework
{ {
Vocalization.ModMonitor.Log(this.stringsFileNames.ElementAt(i)); Vocalization.ModMonitor.Log(this.stringsFileNames.ElementAt(i));
string s = this.stringsFileNames.ElementAt(i); string s = this.stringsFileNames.ElementAt(i);
s = this.stringsFileNames.ElementAt(i).Replace(".xnb", Vocalization.config.translationInfo.getFileExtentionForTranslation(translation)); s = this.stringsFileNames.ElementAt(i).Replace(".xnb", extension);
this.stringsFileNames[i] = s; this.stringsFileNames[i] = s;
Vocalization.ModMonitor.Log(this.stringsFileNames.ElementAt(i)); Vocalization.ModMonitor.Log(this.stringsFileNames.ElementAt(i));
} }
@ -205,7 +208,7 @@ namespace Vocalization.Framework
{ {
Vocalization.ModMonitor.Log(this.festivalFileNames.ElementAt(i)); Vocalization.ModMonitor.Log(this.festivalFileNames.ElementAt(i));
string s = this.festivalFileNames.ElementAt(i); string s = this.festivalFileNames.ElementAt(i);
s = this.festivalFileNames.ElementAt(i).Replace(".xnb", Vocalization.config.translationInfo.getFileExtentionForTranslation(translation)); s = this.festivalFileNames.ElementAt(i).Replace(".xnb", extension);
this.festivalFileNames[i] = s; this.festivalFileNames[i] = s;
Vocalization.ModMonitor.Log(this.festivalFileNames.ElementAt(i)); Vocalization.ModMonitor.Log(this.festivalFileNames.ElementAt(i));
} }
@ -214,7 +217,7 @@ namespace Vocalization.Framework
{ {
Vocalization.ModMonitor.Log(this.eventFileNames.ElementAt(i)); Vocalization.ModMonitor.Log(this.eventFileNames.ElementAt(i));
string s = this.eventFileNames.ElementAt(i); string s = this.eventFileNames.ElementAt(i);
s = this.eventFileNames.ElementAt(i).Replace(".xnb", Vocalization.config.translationInfo.getFileExtentionForTranslation(translation)); s = this.eventFileNames.ElementAt(i).Replace(".xnb", extension);
this.eventFileNames[i] = s; this.eventFileNames[i] = s;
Vocalization.ModMonitor.Log(this.eventFileNames.ElementAt(i)); Vocalization.ModMonitor.Log(this.eventFileNames.ElementAt(i));
} }

View File

@ -0,0 +1,14 @@
namespace Vocalization.Framework
{
/// <summary>The supported language names.</summary>
public enum LanguageName
{
English,
Spanish,
Chinese,
Japanese,
Russian,
German,
Portuguese
}
}

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -39,13 +40,13 @@ namespace Vocalization.Framework.Menus
Rectangle sourceRect = new Rectangle(0, 0, 4, 16); Rectangle sourceRect = new Rectangle(0, 0, 4, 16);
this.sliderButton = new SliderButton("Slider", "Volume", new Rectangle(this.xPositionOnScreen + 100, this.yPositionOnScreen + 220, 4, 16), buttonTexture, bar, sourceRect, 2f, new SliderInformation(SliderStyle.Horizontal, (int)(Vocalization.config.voiceVolume * 100), 1), new StardustCore.Animations.Animation(sourceRect), Color.White, Color.Black, new StardustCore.UIUtilities.MenuComponents.Delegates.Functionality.ButtonFunctionality(null, null, null), false, null, true); this.sliderButton = new SliderButton("Slider", "Volume", new Rectangle(this.xPositionOnScreen + 100, this.yPositionOnScreen + 220, 4, 16), buttonTexture, bar, sourceRect, 2f, new SliderInformation(SliderStyle.Horizontal, (int)(Vocalization.config.voiceVolume * 100), 1), new StardustCore.Animations.Animation(sourceRect), Color.White, Color.Black, new StardustCore.UIUtilities.MenuComponents.Delegates.Functionality.ButtonFunctionality(null, null, null), false, null, true);
Button english = new Button("EnglishButton", "English", new Rectangle(0, 0, 174, 39), new Texture2DExtended(Vocalization.ModHelper, Path.Combine("LooseSprites", "LanguageButtons.xnb"), StardewModdingAPI.ContentSource.GameContent), new Rectangle(0, 0, 174, 39), 1f); Button english = new Button(LanguageName.English.ToString(), "English", new Rectangle(0, 0, 174, 39), new Texture2DExtended(Vocalization.ModHelper, Path.Combine("LooseSprites", "LanguageButtons.xnb"), StardewModdingAPI.ContentSource.GameContent), new Rectangle(0, 0, 174, 39), 1f);
Button spanish = new Button("SpanishButton", "Spanish", new Rectangle(0, 0, 174, 39), new Texture2DExtended(Vocalization.ModHelper, Path.Combine("LooseSprites", "LanguageButtons.xnb"), StardewModdingAPI.ContentSource.GameContent), new Rectangle(0, 39 * 2, 174, 39), 1f); Button spanish = new Button(LanguageName.Spanish.ToString(), "Spanish", new Rectangle(0, 0, 174, 39), new Texture2DExtended(Vocalization.ModHelper, Path.Combine("LooseSprites", "LanguageButtons.xnb"), StardewModdingAPI.ContentSource.GameContent), new Rectangle(0, 39 * 2, 174, 39), 1f);
Button portuguese = new Button("PortugueseButton", "Brazillian Portuguese", new Rectangle(0, 0, 174, 39), new Texture2DExtended(Vocalization.ModHelper, Path.Combine("LooseSprites", "LanguageButtons.xnb"), StardewModdingAPI.ContentSource.GameContent), new Rectangle(0, 39 * 4, 174, 39), 1f); Button portuguese = new Button(LanguageName.Portuguese.ToString(), "Brazillian Portuguese", new Rectangle(0, 0, 174, 39), new Texture2DExtended(Vocalization.ModHelper, Path.Combine("LooseSprites", "LanguageButtons.xnb"), StardewModdingAPI.ContentSource.GameContent), new Rectangle(0, 39 * 4, 174, 39), 1f);
Button russian = new Button("RussianButton", "Russian", new Rectangle(0, 0, 174, 39), new Texture2DExtended(Vocalization.ModHelper, Path.Combine("LooseSprites", "LanguageButtons.xnb"), StardewModdingAPI.ContentSource.GameContent), new Rectangle(0, 39 * 6, 174, 39), 1f); Button russian = new Button(LanguageName.Russian.ToString(), "Russian", new Rectangle(0, 0, 174, 39), new Texture2DExtended(Vocalization.ModHelper, Path.Combine("LooseSprites", "LanguageButtons.xnb"), StardewModdingAPI.ContentSource.GameContent), new Rectangle(0, 39 * 6, 174, 39), 1f);
Button chinese = new Button("ChineseButton", "Chinese", new Rectangle(0, 0, 174, 39), new Texture2DExtended(Vocalization.ModHelper, Path.Combine("LooseSprites", "LanguageButtons.xnb"), StardewModdingAPI.ContentSource.GameContent), new Rectangle(0, 39 * 8, 174, 39), 1f); Button chinese = new Button(LanguageName.Chinese.ToString(), "Chinese", new Rectangle(0, 0, 174, 39), new Texture2DExtended(Vocalization.ModHelper, Path.Combine("LooseSprites", "LanguageButtons.xnb"), StardewModdingAPI.ContentSource.GameContent), new Rectangle(0, 39 * 8, 174, 39), 1f);
Button japanese = new Button("JapaneseButton", "Japanese", new Rectangle(0, 0, 174, 39), new Texture2DExtended(Vocalization.ModHelper, Path.Combine("LooseSprites", "LanguageButtons.xnb"), StardewModdingAPI.ContentSource.GameContent), new Rectangle(0, 39 * 10, 174, 39), 1f); Button japanese = new Button(LanguageName.Japanese.ToString(), "Japanese", new Rectangle(0, 0, 174, 39), new Texture2DExtended(Vocalization.ModHelper, Path.Combine("LooseSprites", "LanguageButtons.xnb"), StardewModdingAPI.ContentSource.GameContent), new Rectangle(0, 39 * 10, 174, 39), 1f);
Button german = new Button("GermanButton", "German", new Rectangle(0, 0, 174, 39), new Texture2DExtended(Vocalization.ModHelper, Path.Combine("LooseSprites", "LanguageButtons.xnb"), StardewModdingAPI.ContentSource.GameContent), new Rectangle(0, 39 * 12, 174, 39), 1f); Button german = new Button(LanguageName.German.ToString(), "German", new Rectangle(0, 0, 174, 39), new Texture2DExtended(Vocalization.ModHelper, Path.Combine("LooseSprites", "LanguageButtons.xnb"), StardewModdingAPI.ContentSource.GameContent), new Rectangle(0, 39 * 12, 174, 39), 1f);
List<Button> buttons = new List<Button> List<Button> buttons = new List<Button>
{ {
english, english,
@ -61,7 +62,7 @@ namespace Vocalization.Framework.Menus
for (int i = 0; i < this.languages.buttons.Count; i++) for (int i = 0; i < this.languages.buttons.Count; i++)
{ {
if (Vocalization.config.translationInfo.CurrentTranslation == this.languages.buttons.ElementAt(i).label) if (Vocalization.config.translationInfo.CurrentTranslation == (LanguageName)Enum.Parse(typeof(LanguageName), this.languages.buttons.ElementAt(i).name))
this.languages.buttonIndex = i; this.languages.buttonIndex = i;
} }
} }
@ -112,10 +113,11 @@ namespace Vocalization.Framework.Menus
return true; return true;
} }
public string getTranslationInfo() public LanguageName getTranslationInfo()
{ {
//Return the name of the button which will have the translation stuff here! //Return the name of the button which will have the translation stuff here!
return this.languages.getCurrentButtonLabel(); string currentName = this.languages.getCurrentButtonName();
return (LanguageName)Enum.Parse(typeof(LanguageName), currentName);
} }
public string getAudioMode() public string getAudioMode()

View File

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.Linq;
using StardewValley; using StardewValley;
namespace Vocalization.Framework namespace Vocalization.Framework
@ -12,15 +12,15 @@ namespace Vocalization.Framework
** Accessors ** Accessors
*********/ *********/
/// <summary>The language names supported by this mod.</summary> /// <summary>The language names supported by this mod.</summary>
public List<string> LanguageNames { get; } = new List<string>(); public LanguageName[] LanguageNames { get; } = (from LanguageName language in Enum.GetValues(typeof(LanguageName)) select language).ToArray();
/// <summary>The current translation mode for the mod, so that it knows what files to load at the beginning of the game.</summary> /// <summary>The current translation mode for the mod, so that it knows what files to load at the beginning of the game.</summary>
public string CurrentTranslation { get; set; } = "English"; public LanguageName CurrentTranslation { get; set; } = LanguageName.English;
/// <summary>Holds the info for what translation has what file extension.</summary> /// <summary>Holds the info for what translation has what file extension.</summary>
public Dictionary<string, string> TranslationFileInfo { get; } = new Dictionary<string, string>(); public Dictionary<LanguageName, string> TranslationFileExtensions { get; } = new Dictionary<LanguageName, string>();
public Dictionary<string, LocalizedContentManager.LanguageCode> TranslationCodes { get; } = new Dictionary<string, LocalizedContentManager.LanguageCode>(); public Dictionary<LanguageName, LocalizedContentManager.LanguageCode> TranslationCodes { get; } = new Dictionary<LanguageName, LocalizedContentManager.LanguageCode>();
/********* /*********
@ -29,43 +29,35 @@ namespace Vocalization.Framework
/// <summary>Construct an instance.</summary> /// <summary>Construct an instance.</summary>
public TranslationInfo() public TranslationInfo()
{ {
this.LanguageNames.Add("English"); this.TranslationFileExtensions.Add(LanguageName.English, ".xnb");
this.LanguageNames.Add("Spanish"); this.TranslationFileExtensions.Add(LanguageName.Spanish, ".es-ES.xnb");
this.LanguageNames.Add("Chinese"); this.TranslationFileExtensions.Add(LanguageName.Chinese, ".zh-CN.xnb");
this.LanguageNames.Add("Japanese"); this.TranslationFileExtensions.Add(LanguageName.Japanese, ".ja-JP.xnb");
this.LanguageNames.Add("Russian"); this.TranslationFileExtensions.Add(LanguageName.Russian, ".ru-RU.xnb");
this.LanguageNames.Add("German"); this.TranslationFileExtensions.Add(LanguageName.German, ".de-DE.xnb");
this.LanguageNames.Add("Brazillian Portuguese"); this.TranslationFileExtensions.Add(LanguageName.Portuguese, ".pt-BR.xnb");
this.TranslationFileInfo.Add("English", ".xnb"); this.TranslationCodes.Add(LanguageName.English, LocalizedContentManager.LanguageCode.en);
this.TranslationFileInfo.Add("Spanish", ".es-ES.xnb"); this.TranslationCodes.Add(LanguageName.Spanish, LocalizedContentManager.LanguageCode.es);
this.TranslationFileInfo.Add("Chinese", ".zh-CN.xnb"); this.TranslationCodes.Add(LanguageName.Chinese, LocalizedContentManager.LanguageCode.zh);
this.TranslationFileInfo.Add("Japanese", ".ja-JP.xnb"); this.TranslationCodes.Add(LanguageName.Japanese, LocalizedContentManager.LanguageCode.ja);
this.TranslationFileInfo.Add("Russian", ".ru-RU.xnb"); this.TranslationCodes.Add(LanguageName.Russian, LocalizedContentManager.LanguageCode.ru);
this.TranslationFileInfo.Add("German", ".de-DE.xnb"); this.TranslationCodes.Add(LanguageName.German, LocalizedContentManager.LanguageCode.de);
this.TranslationFileInfo.Add("Brazillian Portuguese", ".pt-BR.xnb"); this.TranslationCodes.Add(LanguageName.Portuguese, LocalizedContentManager.LanguageCode.pt);
this.TranslationCodes.Add("English", LocalizedContentManager.LanguageCode.en);
this.TranslationCodes.Add("Spanish", LocalizedContentManager.LanguageCode.es);
this.TranslationCodes.Add("Chinese", LocalizedContentManager.LanguageCode.zh);
this.TranslationCodes.Add("Japanese", LocalizedContentManager.LanguageCode.ja);
this.TranslationCodes.Add("Russian", LocalizedContentManager.LanguageCode.ru);
this.TranslationCodes.Add("German", LocalizedContentManager.LanguageCode.de);
this.TranslationCodes.Add("Brazillian Portuguese", LocalizedContentManager.LanguageCode.pt);
} }
public string getTranslationNameFromPath(string fullPath) /// <summary>Get the language name from a string.</summary>
/// <param name="language">The language name.</param>
public string getTranslationName(LanguageName language)
{ {
return Path.GetFileName(fullPath); return language.ToString();
} }
public void changeLocalizedContentManagerFromTranslation(string translation) public void changeLocalizedContentManagerFromTranslation(LanguageName language)
{ {
string tra = this.getTranslationNameFromPath(translation); LocalizedContentManager.CurrentLanguageCode = !this.TranslationCodes.TryGetValue(language, out LocalizedContentManager.LanguageCode code)
LocalizedContentManager.CurrentLanguageCode = !this.TranslationCodes.TryGetValue(tra, out LocalizedContentManager.LanguageCode code)
? LocalizedContentManager.LanguageCode.en ? LocalizedContentManager.LanguageCode.en
: code; : code;
return;
} }
public void resetLocalizationCode() public void resetLocalizationCode()
@ -74,44 +66,39 @@ namespace Vocalization.Framework
} }
/// <summary>Gets the proper file extension for the current translation.</summary> /// <summary>Gets the proper file extension for the current translation.</summary>
public string getFileExtentionForTranslation(string path) /// <param name="language">The translation language name.</param>
public string getFileExtentionForTranslation(LanguageName language)
{ {
/*
bool f = translationFileInfo.TryGetValue(translation, out string value);
if (!f) return ".xnb";
else return value;
*/
string translation = Path.GetFileName(path);
try try
{ {
return this.TranslationFileInfo[translation]; return this.TranslationFileExtensions[language];
} }
catch (Exception err) catch (Exception err)
{ {
Vocalization.ModMonitor.Log(err.ToString()); Vocalization.ModMonitor.Log(err.ToString());
Vocalization.ModMonitor.Log("Attempted to get translation: " + translation); Vocalization.ModMonitor.Log($"Attempted to get translation: {language}");
return ".xnb"; return ".xnb";
} }
} }
/// <summary>Gets the proper XNB for Buildings (aka Blueprints) from the data folder.</summary> /// <summary>Gets the proper XNB for Buildings (aka Blueprints) from the data folder.</summary>
public string getBuildingXNBForTranslation(string translation) public string getBuildingXNBForTranslation(LanguageName language)
{ {
string buildings = "Blueprints"; string buildings = "Blueprints";
return buildings + this.getFileExtentionForTranslation(translation); return buildings + this.getFileExtentionForTranslation(language);
} }
/// <summary>Gets the proper XNB file for the name passed in. Combines the file name with it's proper translation extension.</summary> /// <summary>Gets the proper XNB file for the name passed in. Combines the file name with it's proper translation extension.</summary>
public string getXNBForTranslation(string xnbFileName, string translation) public string getXNBForTranslation(string xnbFileName, LanguageName language)
{ {
return xnbFileName + this.getFileExtentionForTranslation(translation); return xnbFileName + this.getFileExtentionForTranslation(language);
} }
/// <summary>Loads an XNB file from StardewValley/Content</summary> /// <summary>Loads an XNB file from StardewValley/Content</summary>
public string LoadXNBFile(string xnbFileName, string key, string translation) public string LoadXNBFile(string xnbFileName, string key, LanguageName language)
{ {
string xnb = xnbFileName + this.getFileExtentionForTranslation(translation); string xnb = xnbFileName + this.getFileExtentionForTranslation(language);
Dictionary<string, string> loadedDict = Game1.content.Load<Dictionary<string, string>>(xnb); Dictionary<string, string> loadedDict = Game1.content.Load<Dictionary<string, string>>(xnb);
if (!loadedDict.TryGetValue(key, out string loaded)) if (!loadedDict.TryGetValue(key, out string loaded))
@ -122,9 +109,9 @@ namespace Vocalization.Framework
return loaded; return loaded;
} }
public virtual string LoadString(string path, string translation, object sub1, object sub2, object sub3) public virtual string LoadString(string path, LanguageName language, object sub1, object sub2, object sub3)
{ {
string format = this.LoadString(path, translation); string format = this.LoadString(path, language);
try try
{ {
return string.Format(format, sub1, sub2, sub3); return string.Format(format, sub1, sub2, sub3);
@ -134,9 +121,9 @@ namespace Vocalization.Framework
return format; return format;
} }
public virtual string LoadString(string path, string translation, object sub1, object sub2) public virtual string LoadString(string path, LanguageName language, object sub1, object sub2)
{ {
string format = this.LoadString(path, translation); string format = this.LoadString(path, language);
try try
{ {
return string.Format(format, sub1, sub2); return string.Format(format, sub1, sub2);
@ -146,9 +133,9 @@ namespace Vocalization.Framework
return format; return format;
} }
public virtual string LoadString(string path, string translation, object sub1) public virtual string LoadString(string path, LanguageName language, object sub1)
{ {
string format = this.LoadString(path, translation); string format = this.LoadString(path, language);
try try
{ {
return string.Format(format, sub1); return string.Format(format, sub1);
@ -158,16 +145,16 @@ namespace Vocalization.Framework
return format; return format;
} }
public virtual string LoadString(string path, string translation) public virtual string LoadString(string path, LanguageName language)
{ {
this.parseStringPath(path, out string assetName, out string key); this.parseStringPath(path, out string assetName, out string key);
return this.LoadXNBFile(assetName, key, translation); return this.LoadXNBFile(assetName, key, language);
} }
public virtual string LoadString(string path, string translation, params object[] substitutions) public virtual string LoadString(string path, LanguageName language, params object[] substitutions)
{ {
string format = this.LoadString(path, translation); string format = this.LoadString(path, language);
if (substitutions.Length != 0) if (substitutions.Length != 0)
{ {
try try
@ -178,7 +165,7 @@ namespace Vocalization.Framework
} }
return format; return format;
} }
private void parseStringPath(string path, out string assetName, out string key) private void parseStringPath(string path, out string assetName, out string key)
{ {
int length = path.IndexOf(':'); int length = path.IndexOf(':');

View File

@ -10,67 +10,67 @@ namespace Vocalization.Framework
{ {
public class Vocabulary public class Vocabulary
{ {
public static string[] getRandomNegativeItemSlanderNouns(string translation) public static string[] getRandomNegativeItemSlanderNouns(LanguageName language)
{ {
string[] strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeItemNoun"), translation).Split('#'); string[] strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeItemNoun"), language).Split('#');
return strArray; return strArray;
} }
public static string[] getRandomDeliciousAdjectives(string translation, NPC n = null) public static string[] getRandomDeliciousAdjectives(LanguageName language, NPC n = null)
{ {
string[] strArray; string[] strArray;
if (n != null && n.Age == 2) if (n != null && n.Age == 2)
strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomDeliciousAdjective_Child"), translation).Split('#'); strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomDeliciousAdjective_Child"), language).Split('#');
else else
strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomDeliciousAdjective"), translation).Split('#'); strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomDeliciousAdjective"), language).Split('#');
return strArray; return strArray;
} }
public static string[] getRandomNegativeFoodAdjectives(string translation, NPC n = null) public static string[] getRandomNegativeFoodAdjectives(LanguageName language, NPC n = null)
{ {
string[] strArray; string[] strArray;
if (n != null && n.Age == 2) if (n != null && n.Age == 2)
strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeFoodAdjective_Child"), translation).Split('#'); strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeFoodAdjective_Child"), language).Split('#');
else if (n != null && n.Manners == 1) else if (n != null && n.Manners == 1)
strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeFoodAdjective_Polite"), translation).Split('#'); strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeFoodAdjective_Polite"), language).Split('#');
else else
strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeFoodAdjective"), translation).Split('#'); strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeFoodAdjective"), language).Split('#');
return strArray; return strArray;
} }
public static string[] getRandomSlightlyPositiveAdjectivesForEdibleNoun(string translation, NPC n = null) public static string[] getRandomSlightlyPositiveAdjectivesForEdibleNoun(LanguageName language, NPC n = null)
{ {
string[] strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomSlightlyPositiveFoodAdjective"), translation).Split('#'); string[] strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomSlightlyPositiveFoodAdjective"), language).Split('#');
return strArray; return strArray;
} }
public static string[] getRandomNegativeAdjectivesForEventOrPerson(string translation, NPC n = null) public static string[] getRandomNegativeAdjectivesForEventOrPerson(LanguageName language, NPC n = null)
{ {
Random random = new Random((int)Game1.stats.DaysPlayed + (int)Game1.uniqueIDForThisGame / 2); Random random = new Random((int)Game1.stats.DaysPlayed + (int)Game1.uniqueIDForThisGame / 2);
string[] strArray; string[] strArray;
if (n != null && n.Age != 0) if (n != null && n.Age != 0)
strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeAdjective_Child"), translation).Split('#'); strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeAdjective_Child"), language).Split('#');
else if (n != null && n.Gender == 0) else if (n != null && n.Gender == 0)
strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeAdjective_AdultMale"), translation).Split('#'); strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeAdjective_AdultMale"), language).Split('#');
else if (n != null && n.Gender == 1) else if (n != null && n.Gender == 1)
strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeAdjective_AdultFemale"), translation).Split('#'); strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeAdjective_AdultFemale"), language).Split('#');
else else
strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeAdjective_PlaceOrEvent"), translation).Split('#'); strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomNegativeAdjective_PlaceOrEvent"), language).Split('#');
return strArray; return strArray;
} }
public static string[] getRandomPositiveAdjectivesForEventOrPerson(string translation, NPC n = null) public static string[] getRandomPositiveAdjectivesForEventOrPerson(LanguageName language, NPC n = null)
{ {
//Random random = new Random((int)Game1.stats.DaysPlayed + (int)Game1.uniqueIDForThisGame / 2); //Random random = new Random((int)Game1.stats.DaysPlayed + (int)Game1.uniqueIDForThisGame / 2);
string[] strArray; string[] strArray;
if (n != null && n.Age != 0) if (n != null && n.Age != 0)
strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomPositiveAdjective_Child"), translation).Split('#'); strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomPositiveAdjective_Child"), language).Split('#');
else if (n != null && n.Gender == 0) else if (n != null && n.Gender == 0)
strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomPositiveAdjective_AdultMale"), translation).Split('#'); strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomPositiveAdjective_AdultMale"), language).Split('#');
else if (n != null && n.Gender == 1) else if (n != null && n.Gender == 1)
strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomPositiveAdjective_AdultFemale"), translation).Split('#'); strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomPositiveAdjective_AdultFemale"), language).Split('#');
else else
strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomPositiveAdjective_PlaceOrEvent"), translation).Split('#'); strArray = Vocalization.config.translationInfo.LoadString(Path.Combine("Strings", "Lexicon:RandomPositiveAdjective_PlaceOrEvent"), language).Split('#');
return strArray; return strArray;
} }
@ -80,12 +80,12 @@ namespace Vocalization.Framework
} }
/// <summary>Gets a list of all of the possible cooking recipes in Stardew Valley.</summary> /// <summary>Gets a list of all of the possible cooking recipes in Stardew Valley.</summary>
public static List<string> getAllCookingRecipes(string translation) public static List<string> getAllCookingRecipes(LanguageName language)
{ {
List<string> recipes = new List<string>(); List<string> recipes = new List<string>();
Dictionary<string, string> cookingDict = Game1.content.Load<Dictionary<string, string>>(Path.Combine("Data", "TV", Vocalization.config.translationInfo.getXNBForTranslation("CookingChannel", translation))); Dictionary<string, string> cookingDict = Game1.content.Load<Dictionary<string, string>>(Path.Combine("Data", "TV", Vocalization.config.translationInfo.getXNBForTranslation("CookingChannel", language)));
if (Vocalization.config.translationInfo.getTranslationNameFromPath(translation) == "English") if (language == LanguageName.English)
{ {
foreach (KeyValuePair<string, string> pair in cookingDict) foreach (KeyValuePair<string, string> pair in cookingDict)
{ {
@ -105,10 +105,10 @@ namespace Vocalization.Framework
return recipes; return recipes;
} }
public static List<string> getCarpenterStock(string translation) public static List<string> getCarpenterStock(LanguageName language)
{ {
List<string> stock = new List<string>(); List<string> stock = new List<string>();
Vocalization.config.translationInfo.changeLocalizedContentManagerFromTranslation(translation); Vocalization.config.translationInfo.changeLocalizedContentManagerFromTranslation(language);
for (int i = 0; i <= 1854; i++) for (int i = 0; i <= 1854; i++)
{ {
@ -123,10 +123,10 @@ namespace Vocalization.Framework
return stock; return stock;
} }
public static List<string> getMerchantStock(string translation) public static List<string> getMerchantStock(LanguageName language)
{ {
List<string> stock = new List<string>(); List<string> stock = new List<string>();
Dictionary<int, string> objDict = Game1.content.Load<Dictionary<int, string>>(Path.Combine("Data", Vocalization.config.translationInfo.getXNBForTranslation("ObjectInformation", translation))); Dictionary<int, string> objDict = Game1.content.Load<Dictionary<int, string>>(Path.Combine("Data", Vocalization.config.translationInfo.getXNBForTranslation("ObjectInformation", language)));
//Vocalization.ModMonitor.Log("LOAD THE OBJECT INFO: ", LogLevel.Alert); //Vocalization.ModMonitor.Log("LOAD THE OBJECT INFO: ", LogLevel.Alert);
foreach (KeyValuePair<int, string> pair in objDict) foreach (KeyValuePair<int, string> pair in objDict)
{ {
@ -136,14 +136,14 @@ namespace Vocalization.Framework
stock.Add(obj.DisplayName); stock.Add(obj.DisplayName);
} }
} }
foreach (string item in getCarpenterStock(translation)) foreach (string item in getCarpenterStock(language))
stock.Add(item); stock.Add(item);
return stock; return stock;
} }
public static string getProperArticleForWord(string displayName, string translation) public static string getProperArticleForWord(string displayName, LanguageName language)
{ {
Vocalization.config.translationInfo.changeLocalizedContentManagerFromTranslation(translation); Vocalization.config.translationInfo.changeLocalizedContentManagerFromTranslation(language);
string s = Lexicon.getProperArticleForWord(displayName); string s = Lexicon.getProperArticleForWord(displayName);
Vocalization.config.translationInfo.resetLocalizationCode(); Vocalization.config.translationInfo.resetLocalizationCode();
return s; return s;

File diff suppressed because it is too large Load Diff

View File

@ -48,6 +48,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Framework\AudioCues.cs" /> <Compile Include="Framework\AudioCues.cs" />
<Compile Include="Framework\CharacterVoiceCue.cs" /> <Compile Include="Framework\CharacterVoiceCue.cs" />
<Compile Include="Framework\LanguageName.cs" />
<Compile Include="Framework\Menus\VocalizationMenu.cs" /> <Compile Include="Framework\Menus\VocalizationMenu.cs" />
<Compile Include="Framework\ReplacementStrings.cs" /> <Compile Include="Framework\ReplacementStrings.cs" />
<Compile Include="Framework\TranslationInfo.cs" /> <Compile Include="Framework\TranslationInfo.cs" />