mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 18:19:48 +00:00
Enhance localization support by adding namespace and type parameters for base classes
This commit is contained in:
parent
c20b1c6dea
commit
8f2728127d
@ -136,6 +136,8 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private string TB(string fallbackEN) => this.T(fallbackEN, typeof(AssistantBase<TSettings>).Namespace, nameof(AssistantBase<TSettings>));
|
||||||
|
|
||||||
private string SubmitButtonStyle => this.SettingsManager.ConfigurationData.LLMProviders.ShowProviderConfidence ? this.providerSettings.UsedLLMProvider.GetConfidence(this.SettingsManager).StyleBorder(this.SettingsManager) : string.Empty;
|
private string SubmitButtonStyle => this.SettingsManager.ConfigurationData.LLMProviders.ShowProviderConfidence ? this.providerSettings.UsedLLMProvider.GetConfidence(this.SettingsManager).StyleBorder(this.SettingsManager) : string.Empty;
|
||||||
|
|
||||||
protected string? ValidatingProvider(AIStudio.Settings.Provider provider)
|
protected string? ValidatingProvider(AIStudio.Settings.Provider provider)
|
||||||
|
@ -36,6 +36,9 @@ public abstract class MSGComponentBase : ComponentBase, IDisposable, IMessageBus
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string T(string fallbackEN) => this.GetText(this.Lang, fallbackEN);
|
public string T(string fallbackEN) => this.GetText(this.Lang, fallbackEN);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string T(string fallbackEN, string? typeNamespace, string? typeName) => this.GetText(this.Lang, fallbackEN, typeNamespace, typeName);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Implementation of IMessageBusReceiver
|
#region Implementation of IMessageBusReceiver
|
||||||
|
@ -123,8 +123,12 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan
|
|||||||
|
|
||||||
#region Implementation of ILang
|
#region Implementation of ILang
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public string T(string fallbackEN) => this.GetText(this.Lang, fallbackEN);
|
public string T(string fallbackEN) => this.GetText(this.Lang, fallbackEN);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string T(string fallbackEN, string? typeNamespace, string? typeName) => this.GetText(this.Lang, fallbackEN, typeNamespace, typeName);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Implementation of IMessageBusReceiver
|
#region Implementation of IMessageBusReceiver
|
||||||
|
@ -18,4 +18,24 @@ public interface ILang
|
|||||||
/// <param name="fallbackEN">The fallback text in English (US).</param>
|
/// <param name="fallbackEN">The fallback text in English (US).</param>
|
||||||
/// <returns>The text from the language plugin or the fallback text.</returns>
|
/// <returns>The text from the language plugin or the fallback text.</returns>
|
||||||
public string T(string fallbackEN);
|
public string T(string fallbackEN);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tries to get a text from the language plugin.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The given fallback text is used to determine the key for
|
||||||
|
/// the language plugin. Base for the key is the namespace of
|
||||||
|
/// the using component and the fallback text in English (US).
|
||||||
|
/// The given text is hashed. When the key does not exist,
|
||||||
|
/// the fallback text will be returned.<br/>
|
||||||
|
/// <br/>
|
||||||
|
/// You might predefine the namespace and type. This is needed
|
||||||
|
/// when your abstract base class component wants to localize
|
||||||
|
/// text as well.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="fallbackEN">The fallback text in English (US).</param>
|
||||||
|
/// <param name="typeNamespace">The namespace of the type requesting the text, used as part of the key.</param>
|
||||||
|
/// <param name="typeName">The name of the type requesting the text, used as part of the key.</param>
|
||||||
|
/// <returns>The text from the language plugin or the fallback text.</returns>
|
||||||
|
public string T(string fallbackEN, string? typeNamespace, string? typeName);
|
||||||
}
|
}
|
@ -6,10 +6,13 @@ public static class ILangExtensions
|
|||||||
{
|
{
|
||||||
private static readonly ILogger<ILang> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ILang>();
|
private static readonly ILogger<ILang> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ILang>();
|
||||||
|
|
||||||
public static string GetText(this ILang lang, ILanguagePlugin plugin, string fallbackEN)
|
public static string GetText(this ILang lang, ILanguagePlugin plugin, string fallbackEN, string? typeNamespace = null, string? typeName = null)
|
||||||
{
|
{
|
||||||
var type = lang.GetType();
|
var type = lang.GetType();
|
||||||
var ns = $"{type.Namespace!}::{type.Name}".ToUpperInvariant().Replace(".", "::");
|
typeName ??= type.Name;
|
||||||
|
typeNamespace ??= type.Namespace!;
|
||||||
|
|
||||||
|
var ns = $"{typeNamespace}::{typeName}".ToUpperInvariant().Replace(".", "::");
|
||||||
var key = $"root::{ns}::T{fallbackEN.ToFNV32()}";
|
var key = $"root::{ns}::T{fallbackEN.ToFNV32()}";
|
||||||
|
|
||||||
if(plugin is NoPluginLanguage)
|
if(plugin is NoPluginLanguage)
|
||||||
|
Loading…
Reference in New Issue
Block a user