mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Add another translation dictionary that keeps CDATA
This commit is contained in:
parent
fea15287c6
commit
f765e07859
@ -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 <![CDATA[<color=orange>shuttle</color>]]> is currently resting at <![CDATA[<color=lightblue>{0}</color>]]>."
|
||||
},
|
||||
"AchievementTranslations": {
|
||||
|
||||
@ -159,7 +159,7 @@ namespace NewHorizons.Builder.Props
|
||||
var shuttle = ShuttleBuilder.Shuttles[id];
|
||||
var planet = AstroObjectLocator.GetPlanetName(shuttle.GetComponentInParent<AstroObject>());
|
||||
|
||||
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 = $"<NomaiObject>\r\n <TextBlock>\r\n <ID>1</ID>\r\n <Text>{displayText}</Text>\r\n </TextBlock>\r\n</NomaiObject>";
|
||||
|
||||
|
||||
@ -23,6 +23,11 @@ namespace NewHorizons.External.Configs
|
||||
/// </summary>
|
||||
public Dictionary<string, string> UIDictionary;
|
||||
|
||||
/// <summary>
|
||||
/// Translation table for other text, will be taken verbatim without correcting CDATA
|
||||
/// </summary>
|
||||
public Dictionary<string, string> 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<string, string>) (dict[nameof(UIDictionary)] as JObject).ToObject(
|
||||
typeof(Dictionary<string, string>));
|
||||
if (dict.ContainsKey(nameof(OtherDictionary)))
|
||||
OtherDictionary =
|
||||
(Dictionary<string, string>)(dict[nameof(OtherDictionary)] as JObject).ToObject(
|
||||
typeof(Dictionary<string, string>));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -11,12 +11,14 @@ namespace NewHorizons.Handlers
|
||||
private static Dictionary<TextTranslation.Language, Dictionary<string, string>> _shipLogTranslationDictionary = new();
|
||||
private static Dictionary<TextTranslation.Language, Dictionary<string, string>> _dialogueTranslationDictionary = new();
|
||||
private static Dictionary<TextTranslation.Language, Dictionary<string, string>> _uiTranslationDictionary = new();
|
||||
private static Dictionary<TextTranslation.Language, Dictionary<string, string>> _otherTranslationDictionary = new();
|
||||
|
||||
public enum TextType
|
||||
{
|
||||
SHIPLOG,
|
||||
DIALOGUE,
|
||||
UI
|
||||
UI,
|
||||
OTHER
|
||||
}
|
||||
|
||||
public static string GetTranslation(string text, TextType type) => GetTranslation(text, type, true);
|
||||
@ -37,6 +39,9 @@ namespace NewHorizons.Handlers
|
||||
case TextType.UI:
|
||||
dictionary = _uiTranslationDictionary;
|
||||
break;
|
||||
case TextType.OTHER:
|
||||
dictionary = _otherTranslationDictionary;
|
||||
break;
|
||||
default:
|
||||
if (warn) NHLogger.LogVerbose($"Invalid TextType {type}");
|
||||
return text;
|
||||
@ -93,14 +98,27 @@ namespace NewHorizons.Handlers
|
||||
if (!_uiTranslationDictionary.ContainsKey(language)) _uiTranslationDictionary.Add(language, new Dictionary<string, string>());
|
||||
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("<![CDATA[", "").Replace("]]>", "");
|
||||
var value = config.UIDictionary[originalKey].Replace("<", "<").Replace(">", ">").Replace("<![CDATA[", "").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<string, string>());
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user