From f765e078599e0e782b38d2435b3d1e19571fdd8c Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 8 Aug 2023 00:20:47 -0400 Subject: [PATCH] Add another translation dictionary that keeps CDATA --- NewHorizons/Assets/translations/english.json | 4 ++- .../Builder/Props/GravityCannonBuilder.cs | 2 +- .../External/Configs/TranslationConfig.cs | 9 +++++++ NewHorizons/Handlers/TranslationHandler.cs | 26 ++++++++++++++++--- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/NewHorizons/Assets/translations/english.json b/NewHorizons/Assets/translations/english.json index c5e6db88..48df51ee 100644 --- a/NewHorizons/Assets/translations/english.json +++ b/NewHorizons/Assets/translations/english.json @@ -22,7 +22,9 @@ "DEBUG_PLACE_TEXT": "Place Nomai Text", "DEBUG_UNDO": "Undo", "DEBUG_REDO": "Redo", - "Vessel": "Vessel", + "Vessel": "Vessel" + }, + "OtherDictionary": { "NOMAI_SHUTTLE_COMPUTER": "The shuttle]]> is currently resting at {0}]]>." }, "AchievementTranslations": { diff --git a/NewHorizons/Builder/Props/GravityCannonBuilder.cs b/NewHorizons/Builder/Props/GravityCannonBuilder.cs index 9979e7ec..e86ccd42 100644 --- a/NewHorizons/Builder/Props/GravityCannonBuilder.cs +++ b/NewHorizons/Builder/Props/GravityCannonBuilder.cs @@ -159,7 +159,7 @@ namespace NewHorizons.Builder.Props var shuttle = ShuttleBuilder.Shuttles[id]; var planet = AstroObjectLocator.GetPlanetName(shuttle.GetComponentInParent()); - var displayText = TranslationHandler.GetTranslation("NOMAI_SHUTTLE_COMPUTER", TranslationHandler.TextType.UI).Replace("{0}", planet); + var displayText = TranslationHandler.GetTranslation("NOMAI_SHUTTLE_COMPUTER", TranslationHandler.TextType.OTHER).Replace("{0}", planet); NHLogger.Log(displayText); var xmlContent = $"\r\n \r\n 1\r\n {displayText}\r\n \r\n"; diff --git a/NewHorizons/External/Configs/TranslationConfig.cs b/NewHorizons/External/Configs/TranslationConfig.cs index 4f3371ca..7341af9e 100644 --- a/NewHorizons/External/Configs/TranslationConfig.cs +++ b/NewHorizons/External/Configs/TranslationConfig.cs @@ -23,6 +23,11 @@ namespace NewHorizons.External.Configs /// public Dictionary UIDictionary; + /// + /// Translation table for other text, will be taken verbatim without correcting CDATA + /// + public Dictionary OtherDictionary; + #region Achievements+ // This only exists for schema generation, Achievements+ handles the parsing #pragma warning disable 0169 @@ -63,6 +68,10 @@ namespace NewHorizons.External.Configs UIDictionary = (Dictionary) (dict[nameof(UIDictionary)] as JObject).ToObject( typeof(Dictionary)); + if (dict.ContainsKey(nameof(OtherDictionary))) + OtherDictionary = + (Dictionary)(dict[nameof(OtherDictionary)] as JObject).ToObject( + typeof(Dictionary)); } } } \ No newline at end of file diff --git a/NewHorizons/Handlers/TranslationHandler.cs b/NewHorizons/Handlers/TranslationHandler.cs index 62da21ab..2db44131 100644 --- a/NewHorizons/Handlers/TranslationHandler.cs +++ b/NewHorizons/Handlers/TranslationHandler.cs @@ -11,12 +11,14 @@ namespace NewHorizons.Handlers private static Dictionary> _shipLogTranslationDictionary = new(); private static Dictionary> _dialogueTranslationDictionary = new(); private static Dictionary> _uiTranslationDictionary = new(); + private static Dictionary> _otherTranslationDictionary = new(); public enum TextType { SHIPLOG, DIALOGUE, - UI + UI, + OTHER } public static string GetTranslation(string text, TextType type) => GetTranslation(text, type, true); @@ -36,6 +38,9 @@ namespace NewHorizons.Handlers break; case TextType.UI: dictionary = _uiTranslationDictionary; + break; + case TextType.OTHER: + dictionary = _otherTranslationDictionary; break; default: if (warn) NHLogger.LogVerbose($"Invalid TextType {type}"); @@ -93,14 +98,27 @@ namespace NewHorizons.Handlers if (!_uiTranslationDictionary.ContainsKey(language)) _uiTranslationDictionary.Add(language, new Dictionary()); foreach (var originalKey in config.UIDictionary.Keys) { - // Don't remove CDATA from UI - var key = originalKey.Replace("<", "<").Replace(">", ">"); - var value = config.UIDictionary[originalKey].Replace("<", "<").Replace(">", ">"); + var key = originalKey.Replace("<", "<").Replace(">", ">").Replace("", ""); + var value = config.UIDictionary[originalKey].Replace("<", "<").Replace(">", ">").Replace("", ""); if (!_uiTranslationDictionary[language].ContainsKey(key)) _uiTranslationDictionary[language].Add(key, value); else _uiTranslationDictionary[language][key] = value; } } + + if (config.OtherDictionary != null && config.OtherDictionary.Count() > 0) + { + if (!_otherTranslationDictionary.ContainsKey(language)) _otherTranslationDictionary.Add(language, new Dictionary()); + foreach (var originalKey in config.OtherDictionary.Keys) + { + // Don't remove CDATA + var key = originalKey.Replace("<", "<").Replace(">", ">"); + var value = config.OtherDictionary[originalKey].Replace("<", "<").Replace(">", ">"); + + if (!_otherTranslationDictionary[language].ContainsKey(key)) _otherTranslationDictionary[language].Add(key, value); + else _otherTranslationDictionary[language][key] = value; + } + } } public static void AddDialogue(string rawText, bool trimRawTextForKey = false, params string[] rawPreText)