From ccd3e297e6c58a5138cd3db0d89302c9c103a0e6 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 8 Mar 2024 10:59:25 -0500 Subject: [PATCH] Keys are now much more forgiving (ignores whitespace casing why not) --- NewHorizons/Handlers/TranslationHandler.cs | 15 +++++++++++++-- NewHorizons/Utility/NewHorizonExtensions.cs | 6 ++++++ NewHorizons/manifest.json | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Handlers/TranslationHandler.cs b/NewHorizons/Handlers/TranslationHandler.cs index 1695d954..4e2eac58 100644 --- a/NewHorizons/Handlers/TranslationHandler.cs +++ b/NewHorizons/Handlers/TranslationHandler.cs @@ -1,8 +1,10 @@ using NewHorizons.External.Configs; +using NewHorizons.Utility; using NewHorizons.Utility.OWML; using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; namespace NewHorizons.Handlers { @@ -49,8 +51,17 @@ namespace NewHorizons.Handlers // Get the translated text if (dictionary.TryGetValue(language, out var table)) + { if (table.TryGetValue(text, out var translatedText)) + { return translatedText; + } + // Try without whitespace if its missing + else if (table.TryGetValue(text.TruncateWhitespace(), out translatedText)) + { + return translatedText; + } + } if (warn) NHLogger.LogVerbose($"Defaulting to english for {text}"); @@ -85,8 +96,8 @@ namespace NewHorizons.Handlers if (!_dialogueTranslationDictionary.ContainsKey(language)) _dialogueTranslationDictionary.Add(language, new Dictionary()); foreach (var originalKey in config.DialogueDictionary.Keys) { - var key = originalKey.Replace("<", "<").Replace(">", ">").Replace("", ""); - var value = config.DialogueDictionary[originalKey].Replace("<", "<").Replace(">", ">").Replace("", ""); + var key = originalKey.Replace("\\n", "\n").TruncateWhitespace().Replace("<", "<").Replace(">", ">").Replace("", ""); + var value = config.DialogueDictionary[originalKey].Replace("\\n", "\n").Replace("<", "<").Replace(">", ">").Replace("", ""); if (!_dialogueTranslationDictionary[language].ContainsKey(key)) _dialogueTranslationDictionary[language].Add(key, value); else _dialogueTranslationDictionary[language][key] = value; diff --git a/NewHorizons/Utility/NewHorizonExtensions.cs b/NewHorizons/Utility/NewHorizonExtensions.cs index 6e349e5d..1815ed87 100644 --- a/NewHorizons/Utility/NewHorizonExtensions.cs +++ b/NewHorizons/Utility/NewHorizonExtensions.cs @@ -350,5 +350,11 @@ namespace NewHorizons.Utility { return parentNode.ChildNodes.Cast().First(node => node.LocalName == tagName); } + + public static string TruncateWhitespace(this string text) + { + // return Regex.Replace(text.Trim(), @"[^\S\r\n]+", "GUH"); + return Regex.Replace(text.Trim(), @"\s+", " ").ToLowerInvariant(); + } } } diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index 408ac0a9..96641cc0 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -4,7 +4,7 @@ "author": "xen, Bwc9876, JohnCorby, MegaPiggy, Clay, Trifid, and friends", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "1.18.9", + "version": "1.18.10", "owmlVersion": "2.9.8", "dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ], "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_CommonResources" ],