mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Keys are now much more forgiving (ignores whitespace casing why not)
This commit is contained in:
parent
9e8f8dd1df
commit
ccd3e297e6
@ -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<string, string>());
|
||||
foreach (var originalKey in config.DialogueDictionary.Keys)
|
||||
{
|
||||
var key = originalKey.Replace("<", "<").Replace(">", ">").Replace("<![CDATA[", "").Replace("]]>", "");
|
||||
var value = config.DialogueDictionary[originalKey].Replace("<", "<").Replace(">", ">").Replace("<![CDATA[", "").Replace("]]>", "");
|
||||
var key = originalKey.Replace("\\n", "\n").TruncateWhitespace().Replace("<", "<").Replace(">", ">").Replace("<![CDATA[", "").Replace("]]>", "");
|
||||
var value = config.DialogueDictionary[originalKey].Replace("\\n", "\n").Replace("<", "<").Replace(">", ">").Replace("<![CDATA[", "").Replace("]]>", "");
|
||||
|
||||
if (!_dialogueTranslationDictionary[language].ContainsKey(key)) _dialogueTranslationDictionary[language].Add(key, value);
|
||||
else _dialogueTranslationDictionary[language][key] = value;
|
||||
|
||||
@ -350,5 +350,11 @@ namespace NewHorizons.Utility
|
||||
{
|
||||
return parentNode.ChildNodes.Cast<XmlNode>().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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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" ],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user