Add localized warp rich presence

This commit is contained in:
Nick 2022-08-21 22:55:32 -04:00
parent e7bfb53c58
commit 301e36bb37
5 changed files with 24 additions and 21 deletions

View File

@ -13,7 +13,8 @@
"ENGAGE_WARP_PROMPT": "Engage Warp To {0}",
"WARP_LOCKED": "AUTOPILOT LOCKED TO:\n{0}",
"LOCK_AUTOPILOT_WARP": "Lock Autopilot to Star System",
"RICH_PRESENCE_EXPLORING": "Exploring {0}."
"RICH_PRESENCE_EXPLORING": "Exploring {0}.",
"RICH_PRESENCE_WARPING": "Warping to {0}."
},
"AchievementTranslations": {
"NH_EATEN_OUTSIDE_BRAMBLE": {

View File

@ -13,7 +13,8 @@
"ENGAGE_WARP_PROMPT": "Engagez la distorsion vers {0}",
"WARP_LOCKED": "PILOTE AUTOMATIQUE VISÉ SUR:\n{0}",
"LOCK_AUTOPILOT_WARP": "Visez le pilote automatique",
"RICH_PRESENCE_EXPLORING": "En explorant {0}."
"RICH_PRESENCE_EXPLORING": "En explorant {0}.",
"RICH_PRESENCE_WARPING": "En route vers {0}."
},
"AchievementTranslations": {
"NH_EATEN_OUTSIDE_BRAMBLE": {

View File

@ -2,6 +2,8 @@ using NewHorizons.External.Configs;
using System;
using System.Collections.Generic;
using System.Linq;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Handlers
{
public static class TranslationHandler
@ -18,11 +20,6 @@ namespace NewHorizons.Handlers
}
public static string GetTranslation(string text, TextType type)
{
return GetTranslation(text, type, out var _);
}
public static string GetTranslation(string text, TextType type, out TextTranslation.Language translatedLanguage)
{
Dictionary<TextTranslation.Language, Dictionary<string, string>> dictionary;
var language = TextTranslation.Get().m_language;
@ -39,31 +36,25 @@ namespace NewHorizons.Handlers
dictionary = _uiTranslationDictionary;
break;
default:
translatedLanguage = TextTranslation.Language.UNKNOWN;
Logger.LogVerbose($"Invalid TextType {type}");
return text;
}
// Get the translated text
if (dictionary.TryGetValue(language, out var table))
{
if (table.TryGetValue(text, out var translatedText))
{
translatedLanguage = language;
return translatedText;
}
}
Logger.LogVerbose($"Defaulting to english for {text}");
// Try to default to English
if (dictionary.TryGetValue(TextTranslation.Language.ENGLISH, out var englishTable))
{
if (englishTable.TryGetValue(text, out var englishText))
{
translatedLanguage = TextTranslation.Language.ENGLISH;
return englishText;
}
}
Logger.LogVerbose($"Defaulting to key for {text}");
// Default to the key
translatedLanguage = TextTranslation.Language.UNKNOWN;
return text;
}

View File

@ -200,7 +200,8 @@ namespace NewHorizons
AchievementHandler.Init();
VoiceHandler.Init();
RichPresenceHandler.Init();
OnStarSystemLoaded.AddListener(RichPresenceHandler.SetUpSolarSystem);
OnStarSystemLoaded.AddListener(RichPresenceHandler.OnStarSystemLoaded);
OnChangeStarSystem.AddListener(RichPresenceHandler.OnChangeStarSystem);
LoadAddonManifest("Assets/addon-manifest.json", this);
}

View File

@ -5,6 +5,7 @@ using System;
using System.IO;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.OtherMods.OWRichPresence
@ -49,7 +50,7 @@ namespace NewHorizons.OtherMods.OWRichPresence
API.CreateTrigger(go, sector, message, name.Replace(" ", "").Replace("'", "").ToLowerInvariant());
}
public static void SetUpSolarSystem(string name)
public static void OnStarSystemLoaded(string name)
{
if (name == "SolarSystem") return;
@ -58,5 +59,13 @@ namespace NewHorizons.OtherMods.OWRichPresence
API.SetCurrentRootPresence(message, "sun");
}
public static void OnChangeStarSystem(string destination)
{
var localizedName = ShipLogStarChartMode.UniqueIDToName(destination);
var message = TranslationHandler.GetTranslation("RICH_PRESENCE_WARPING", TranslationHandler.TextType.UI).Replace("{0}", localizedName);
API.SetRichPresence(message, "newhorizons");
}
}
}