From 2981da577bb61b1d18a86bd6db2fd2fdf4d6e698 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sat, 3 May 2025 21:45:52 +0200 Subject: [PATCH] Add I18N class for static localization --- .../Layout/MainLayout.razor.cs | 2 ++ .../Tools/PluginSystem/I18N.cs | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 app/MindWork AI Studio/Tools/PluginSystem/I18N.cs diff --git a/app/MindWork AI Studio/Layout/MainLayout.razor.cs b/app/MindWork AI Studio/Layout/MainLayout.razor.cs index 934dc358..03e7b4ad 100644 --- a/app/MindWork AI Studio/Layout/MainLayout.razor.cs +++ b/app/MindWork AI Studio/Layout/MainLayout.razor.cs @@ -206,6 +206,8 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan break; case Event.PLUGINS_RELOADED: + this.Lang = await this.SettingsManager.GetActiveLanguagePlugin(); + I18N.Init(this.Lang); await this.InvokeAsync(this.StateHasChanged); break; } diff --git a/app/MindWork AI Studio/Tools/PluginSystem/I18N.cs b/app/MindWork AI Studio/Tools/PluginSystem/I18N.cs new file mode 100644 index 00000000..c327da48 --- /dev/null +++ b/app/MindWork AI Studio/Tools/PluginSystem/I18N.cs @@ -0,0 +1,30 @@ +namespace AIStudio.Tools.PluginSystem; + +public class I18N : ILang +{ + public static readonly I18N I = new(); + private static readonly ILogger LOG = Program.LOGGER_FACTORY.CreateLogger(); + + private ILanguagePlugin language = PluginFactory.BaseLanguage; + + private I18N() + { + } + + public static void Init(ILanguagePlugin language) => I.language = language; + + #region Implementation of ILang + + public string T(string fallbackEN) + { + LOG.LogWarning("Using I18N.I.T without namespace and type is probably wrong, because the I18N key collection process of the build system will not find those keys."); + return this.GetText(this.language, fallbackEN); + } + + public string T(string fallbackEN, string? typeNamespace, string? typeName) + { + return this.GetText(this.language, fallbackEN, typeNamespace, typeName); + } + + #endregion +} \ No newline at end of file