mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 10:39:47 +00:00
Provide the active language plugin
This commit is contained in:
parent
adcd199aff
commit
55c472d819
@ -5,6 +5,7 @@ using System.Text.Json.Serialization;
|
|||||||
using AIStudio.Provider;
|
using AIStudio.Provider;
|
||||||
using AIStudio.Settings.DataModel;
|
using AIStudio.Settings.DataModel;
|
||||||
using AIStudio.Tools.PluginSystem;
|
using AIStudio.Tools.PluginSystem;
|
||||||
|
using AIStudio.Tools.Services;
|
||||||
|
|
||||||
// ReSharper disable NotAccessedPositionalProperty.Local
|
// ReSharper disable NotAccessedPositionalProperty.Local
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ namespace AIStudio.Settings;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The settings manager.
|
/// The settings manager.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class SettingsManager(ILogger<SettingsManager> logger)
|
public sealed class SettingsManager(ILogger<SettingsManager> logger, RustService rustService)
|
||||||
{
|
{
|
||||||
private const string SETTINGS_FILENAME = "settings.json";
|
private const string SETTINGS_FILENAME = "settings.json";
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ public sealed class SettingsManager(ILogger<SettingsManager> logger)
|
|||||||
};
|
};
|
||||||
|
|
||||||
private readonly ILogger<SettingsManager> logger = logger;
|
private readonly ILogger<SettingsManager> logger = logger;
|
||||||
|
private readonly RustService rustService = rustService;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The directory where the configuration files are stored.
|
/// The directory where the configuration files are stored.
|
||||||
@ -150,6 +152,46 @@ public sealed class SettingsManager(ILogger<SettingsManager> logger)
|
|||||||
/// <returns>True, when the plugin is enabled, false otherwise.</returns>
|
/// <returns>True, when the plugin is enabled, false otherwise.</returns>
|
||||||
public bool IsPluginEnabled(IPluginMetadata plugin) => this.ConfigurationData.EnabledPlugins.Contains(plugin.Id);
|
public bool IsPluginEnabled(IPluginMetadata plugin) => this.ConfigurationData.EnabledPlugins.Contains(plugin.Id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the active language plugin.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The active language plugin.</returns>
|
||||||
|
public async Task<ILanguagePlugin> GetActiveLanguagePlugin()
|
||||||
|
{
|
||||||
|
switch (this.ConfigurationData.App.LanguageBehavior)
|
||||||
|
{
|
||||||
|
case LangBehavior.AUTO:
|
||||||
|
var languageCode = await this.rustService.ReadUserLanguage();
|
||||||
|
var languagePlugin = PluginFactory.RunningPlugins.FirstOrDefault(x => x is ILanguagePlugin langPlug && langPlug.IETFTag == languageCode);
|
||||||
|
if (languagePlugin is null)
|
||||||
|
return PluginFactory.BaseLanguage;
|
||||||
|
|
||||||
|
if (languagePlugin is ILanguagePlugin langPlugin)
|
||||||
|
return langPlugin;
|
||||||
|
|
||||||
|
this.logger.LogError("The language plugin is not a language plugin.");
|
||||||
|
return PluginFactory.BaseLanguage;
|
||||||
|
|
||||||
|
case LangBehavior.MANUAL:
|
||||||
|
var pluginId = this.ConfigurationData.App.LanguagePluginId;
|
||||||
|
var plugin = PluginFactory.RunningPlugins.FirstOrDefault(x => x.Id == pluginId);
|
||||||
|
if (plugin is null)
|
||||||
|
{
|
||||||
|
this.logger.LogWarning($"The chosen language plugin (id='{pluginId}') is not available.");
|
||||||
|
return PluginFactory.BaseLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin is ILanguagePlugin chosenLangPlugin)
|
||||||
|
return chosenLangPlugin;
|
||||||
|
|
||||||
|
this.logger.LogError("The chosen language plugin is not a language plugin.");
|
||||||
|
return PluginFactory.BaseLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.LogError("The language behavior is unknown.");
|
||||||
|
return PluginFactory.BaseLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
[SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")]
|
[SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")]
|
||||||
public Provider GetPreselectedProvider(Tools.Components component, string? currentProviderId = null, bool usePreselectionBeforeCurrentProvider = false)
|
public Provider GetPreselectedProvider(Tools.Components component, string? currentProviderId = null, bool usePreselectionBeforeCurrentProvider = false)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user