mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Fix falling back to english failing
This commit is contained in:
parent
d5968c7588
commit
630ee9e375
@ -2,9 +2,11 @@ using NewHorizons.External.Configs;
|
|||||||
using NewHorizons.Utility;
|
using NewHorizons.Utility;
|
||||||
using NewHorizons.Utility.OWML;
|
using NewHorizons.Utility.OWML;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using static TextTranslation;
|
||||||
|
|
||||||
namespace NewHorizons.Handlers
|
namespace NewHorizons.Handlers
|
||||||
{
|
{
|
||||||
@ -50,30 +52,46 @@ namespace NewHorizons.Handlers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the translated text
|
// Get the translated text
|
||||||
if (dictionary.TryGetValue(language, out var table))
|
if (TryGetTranslatedText(dictionary, language, text, out var translatedText))
|
||||||
{
|
{
|
||||||
if (table.TryGetValue(text, out var translatedText))
|
return translatedText;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (warn)
|
||||||
|
{
|
||||||
|
NHLogger.LogVerbose($"Defaulting to english for {text}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TryGetTranslatedText(dictionary, Language.ENGLISH, text, out translatedText))
|
||||||
|
{
|
||||||
|
return translatedText;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (warn)
|
||||||
|
{
|
||||||
|
NHLogger.LogVerbose($"Defaulting to key for {text}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool TryGetTranslatedText(Dictionary<Language, Dictionary<string, string>> dict, Language language, string text, out string translatedText)
|
||||||
|
{
|
||||||
|
if (dict.TryGetValue(language, out var table))
|
||||||
|
{
|
||||||
|
if (table.TryGetValue(text, out translatedText))
|
||||||
{
|
{
|
||||||
return translatedText;
|
return true;
|
||||||
}
|
}
|
||||||
// Try without whitespace if its missing
|
// Try without whitespace if its missing
|
||||||
else if (table.TryGetValue(text.TruncateWhitespaceAndToLower(), out translatedText))
|
else if (table.TryGetValue(text.TruncateWhitespaceAndToLower(), out translatedText))
|
||||||
{
|
{
|
||||||
return translatedText;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (warn) NHLogger.LogVerbose($"Defaulting to english for {text}");
|
translatedText = null;
|
||||||
|
return false;
|
||||||
// Try to default to English
|
|
||||||
if (dictionary.TryGetValue(TextTranslation.Language.ENGLISH, out var englishTable))
|
|
||||||
if (englishTable.TryGetValue(text, out var englishText))
|
|
||||||
return englishText;
|
|
||||||
|
|
||||||
if (warn) NHLogger.LogVerbose($"Defaulting to key for {text}");
|
|
||||||
|
|
||||||
// Default to the key
|
|
||||||
return text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RegisterTranslation(TextTranslation.Language language, TranslationConfig config)
|
public static void RegisterTranslation(TextTranslation.Language language, TranslationConfig config)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user