Add language plugin support to MainLayout.

This commit is contained in:
Thorsten Sommer 2025-04-17 12:38:23 +02:00
parent 088e4ad7e3
commit 19888ff74d
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -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<bool>(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);