From 19888ff74d4442a837b2e150f82b668a57c6321d Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Thu, 17 Apr 2025 12:38:23 +0200 Subject: [PATCH] Add language plugin support to MainLayout. --- app/MindWork AI Studio/Layout/MainLayout.razor.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/MindWork AI Studio/Layout/MainLayout.razor.cs b/app/MindWork AI Studio/Layout/MainLayout.razor.cs index b80de4a5..b249d879 100644 --- a/app/MindWork AI Studio/Layout/MainLayout.razor.cs +++ b/app/MindWork AI Studio/Layout/MainLayout.razor.cs @@ -12,7 +12,7 @@ using DialogOptions = AIStudio.Dialogs.DialogOptions; namespace AIStudio.Layout; -public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, IDisposable +public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILang, IDisposable { [Inject] private SettingsManager SettingsManager { get; init; } = null!; @@ -38,6 +38,8 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, IDis [Inject] private MudTheme ColorTheme { get; init; } = null!; + private ILanguagePlugin Lang { get; set; } = PluginFactory.BaseLanguage; + private string PaddingLeft => this.navBarOpen ? $"padding-left: {NAVBAR_EXPANDED_WIDTH_INT - NAVBAR_COLLAPSED_WIDTH_INT}em;" : "padding-left: 0em;"; private const int NAVBAR_COLLAPSED_WIDTH_INT = 4; @@ -78,7 +80,7 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, IDis // Read the user language from Rust: // var userLanguage = await this.RustService.ReadUserLanguage(); - this.Logger.LogInformation($"The user language is: '{userLanguage}'"); + this.Logger.LogInformation($"The OS says '{userLanguage}' is the user language."); // Ensure that all settings are loaded: await this.SettingsManager.LoadSettings(); @@ -105,6 +107,9 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, IDis // Send a message to start the plugin system: await this.MessageBus.SendMessage(this, Event.STARTUP_PLUGIN_SYSTEM); + // Load the language plugin: + this.Lang = await this.SettingsManager.GetActiveLanguagePlugin(); + await this.themeProvider.WatchSystemPreference(this.SystemeThemeChanged); await this.UpdateThemeConfiguration(); this.LoadNavItems(); @@ -119,6 +124,12 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, IDis #endregion + #region Implementation of ILang + + public string T(string fallbackEN) => this.GetText(this.Lang, fallbackEN); + + #endregion + #region Implementation of IMessageBusReceiver public string ComponentName => nameof(MainLayout);