diff --git a/app/MindWork AI Studio/Components/MSGComponentBase.cs b/app/MindWork AI Studio/Components/MSGComponentBase.cs index fa0c456d..c4c3a49a 100644 --- a/app/MindWork AI Studio/Components/MSGComponentBase.cs +++ b/app/MindWork AI Studio/Components/MSGComponentBase.cs @@ -35,26 +35,7 @@ public abstract class MSGComponentBase : ComponentBase, IDisposable, IMessageBus #region Implementation of ILang /// - public string T(string fallbackEN) - { - var type = this.GetType(); - var ns = $"{type.Namespace!}::{type.Name}".ToUpperInvariant().Replace(".", "::"); - var key = $"root::{ns}::T{fallbackEN.ToFNV32()}"; - - if(this.Lang is NoPluginLanguage) - return fallbackEN; - - if(this.Lang.TryGetText(key, out var text, logWarning: false)) - { - if(string.IsNullOrWhiteSpace(text)) - return fallbackEN; - - return text; - } - - this.Logger.LogWarning($"Missing translation key '{key}' for content '{fallbackEN}'."); - return fallbackEN; - } + public string T(string fallbackEN) => this.GetText(this.Lang, fallbackEN); #endregion diff --git a/app/MindWork AI Studio/Tools/PluginSystem/ILangExtensions.cs b/app/MindWork AI Studio/Tools/PluginSystem/ILangExtensions.cs new file mode 100644 index 00000000..8b457b04 --- /dev/null +++ b/app/MindWork AI Studio/Tools/PluginSystem/ILangExtensions.cs @@ -0,0 +1,29 @@ +using SharedTools; + +namespace AIStudio.Tools.PluginSystem; + +public static class ILangExtensions +{ + private static readonly ILogger LOGGER = Program.LOGGER_FACTORY.CreateLogger(); + + public static string GetText(this ILang lang, ILanguagePlugin plugin, string fallbackEN) + { + var type = lang.GetType(); + var ns = $"{type.Namespace!}::{type.Name}".ToUpperInvariant().Replace(".", "::"); + var key = $"root::{ns}::T{fallbackEN.ToFNV32()}"; + + if(plugin is NoPluginLanguage) + return fallbackEN; + + if(plugin.TryGetText(key, out var text, logWarning: false)) + { + if(string.IsNullOrWhiteSpace(text)) + return fallbackEN; + + return text; + } + + LOGGER.LogWarning($"Missing translation key '{key}' for content '{fallbackEN}'."); + return fallbackEN; + } +} \ No newline at end of file