From ce49b0d51fffc61257285c2108ca3a1e2d358eff Mon Sep 17 00:00:00 2001 From: Haselnussbomber Date: Fri, 25 Apr 2025 20:59:44 +0200 Subject: [PATCH] SeStringEvaluator: fallback to games ClientLanguage (#2261) --- .../Game/Text/Evaluator/SeStringEvaluator.cs | 27 ++++++++++++++----- .../Data/Widgets/SeStringCreatorWidget.cs | 3 ++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Dalamud/Game/Text/Evaluator/SeStringEvaluator.cs b/Dalamud/Game/Text/Evaluator/SeStringEvaluator.cs index 05ad3c496..2ccb3ff47 100644 --- a/Dalamud/Game/Text/Evaluator/SeStringEvaluator.cs +++ b/Dalamud/Game/Text/Evaluator/SeStringEvaluator.cs @@ -51,6 +51,9 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator { private static readonly ModuleLog Log = new("SeStringEvaluator"); + [ServiceManager.ServiceDependency] + private readonly ClientState.ClientState clientState = Service.Get(); + [ServiceManager.ServiceDependency] private readonly DataManager dataManager = Service.Get(); @@ -92,7 +95,7 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator if (str.IsTextOnly()) return new(str); - var lang = language ?? this.dalamudConfiguration.EffectiveLanguage.ToClientLanguage(); + var lang = language ?? this.GetEffectiveClientLanguage(); // TODO: remove culture info toggling after supporting CultureInfo for SeStringBuilder.Append, // and then remove try...finally block (discard builder from the pool on exception) @@ -116,7 +119,7 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator Span localParameters = default, ClientLanguage? language = null) { - var lang = language ?? this.dalamudConfiguration.EffectiveLanguage.ToClientLanguage(); + var lang = language ?? this.GetEffectiveClientLanguage(); if (!this.dataManager.GetExcelSheet(lang).TryGetRow(addonId, out var addonRow)) return default; @@ -130,7 +133,7 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator Span localParameters = default, ClientLanguage? language = null) { - var lang = language ?? this.dalamudConfiguration.EffectiveLanguage.ToClientLanguage(); + var lang = language ?? this.GetEffectiveClientLanguage(); if (!this.dataManager.GetExcelSheet(lang).TryGetRow(lobbyId, out var lobbyRow)) return default; @@ -144,7 +147,7 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator Span localParameters = default, ClientLanguage? language = null) { - var lang = language ?? this.dalamudConfiguration.EffectiveLanguage.ToClientLanguage(); + var lang = language ?? this.GetEffectiveClientLanguage(); if (!this.dataManager.GetExcelSheet(lang).TryGetRow(logMessageId, out var logMessageRow)) return default; @@ -155,7 +158,7 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator /// public string EvaluateActStr(ActionKind actionKind, uint id, ClientLanguage? language = null) => this.actStrCache.GetOrAdd( - new(actionKind, id, language ?? this.dalamudConfiguration.EffectiveLanguage.ToClientLanguage()), + new(actionKind, id, language ?? this.GetEffectiveClientLanguage()), static (key, t) => t.EvaluateFromAddon(2026, [key.Kind.GetActStrId(key.Id)], key.Language) .ExtractText() .StripSoftHyphen(), @@ -164,7 +167,7 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator /// public string EvaluateObjStr(ObjectKind objectKind, uint id, ClientLanguage? language = null) => this.objStrCache.GetOrAdd( - new(objectKind, id, language ?? this.dalamudConfiguration.EffectiveLanguage.ToClientLanguage()), + new(objectKind, id, language ?? this.GetEffectiveClientLanguage()), static (key, t) => t.EvaluateFromAddon(2025, [key.Kind.GetObjStrId(key.Id)], key.Language) .ExtractText() .StripSoftHyphen(), @@ -183,6 +186,18 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator private static uint ConvertRawToMapPosY(Lumina.Excel.Sheets.Map map, float y) => ConvertRawToMapPos(map, map.OffsetY, y); + private ClientLanguage GetEffectiveClientLanguage() + { + return this.dalamudConfiguration.EffectiveLanguage switch + { + "ja" => ClientLanguage.Japanese, + "en" => ClientLanguage.English, + "de" => ClientLanguage.German, + "fr" => ClientLanguage.French, + _ => this.clientState.ClientLanguage, + }; + } + private SeStringBuilder EvaluateAndAppendTo( SeStringBuilder builder, ReadOnlySeStringSpan str, diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/SeStringCreatorWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/SeStringCreatorWidget.cs index 71d4277a7..c45e0cdfb 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/SeStringCreatorWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/SeStringCreatorWidget.cs @@ -6,6 +6,7 @@ using System.Text; using Dalamud.Configuration.Internal; using Dalamud.Data; using Dalamud.Game; +using Dalamud.Game.ClientState; using Dalamud.Game.Text.Evaluator; using Dalamud.Game.Text.Noun.Enums; using Dalamud.Game.Text.SeStringHandling; @@ -168,7 +169,7 @@ internal class SeStringCreatorWidget : IDataWindowWidget /// public void Load() { - this.language = Service.Get().EffectiveLanguage.ToClientLanguage(); + this.language = Service.Get().ClientLanguage; this.UpdateInputString(false); this.Ready = true; }