mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-08-21 15:32:56 +00:00
Implemented the language plugin logic
This commit is contained in:
parent
568a4270ae
commit
bcd0138a96
21
app/MindWork AI Studio/Tools/PluginSystem/ILanguagePlugin.cs
Normal file
21
app/MindWork AI Studio/Tools/PluginSystem/ILanguagePlugin.cs
Normal file
@ -0,0 +1,21 @@
|
||||
namespace AIStudio.Tools.PluginSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contract for a language plugin.
|
||||
/// </summary>
|
||||
public interface ILanguagePlugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Tries to get a text from the language plugin.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When the key does not exist, the value will be an empty string.
|
||||
/// Please note that the key is case-sensitive. Furthermore, the keys
|
||||
/// are in the format "root::key". That means that the keys are
|
||||
/// hierarchical and separated by "::".
|
||||
/// </remarks>
|
||||
/// <param name="key">The key to use to get the text.</param>
|
||||
/// <param name="value">The desired text.</param>
|
||||
/// <returns>True if the key exists, false otherwise.</returns>
|
||||
public bool TryGetText(string key, out string value);
|
||||
}
|
48
app/MindWork AI Studio/Tools/PluginSystem/PluginLanguage.cs
Normal file
48
app/MindWork AI Studio/Tools/PluginSystem/PluginLanguage.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using Lua;
|
||||
|
||||
namespace AIStudio.Tools.PluginSystem;
|
||||
|
||||
public sealed class PluginLanguage : PluginBase, ILanguagePlugin
|
||||
{
|
||||
private readonly Dictionary<string, string> content = [];
|
||||
|
||||
private ILanguagePlugin? baseLanguage;
|
||||
|
||||
public PluginLanguage(string path, LuaState state, PluginType type) : base(path, state, type)
|
||||
{
|
||||
if (this.TryInitUITextContent(out var issue, out var readContent))
|
||||
this.content = readContent;
|
||||
else
|
||||
this.pluginIssues.Add(issue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the base language plugin. This plugin will be used to fill in missing keys.
|
||||
/// </summary>
|
||||
/// <param name="baseLanguagePlugin">The base language plugin to use.</param>
|
||||
public void SetBaseLanguage(ILanguagePlugin baseLanguagePlugin) => this.baseLanguage = baseLanguagePlugin;
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get a text from the language plugin.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When the key neither in the base language nor in this language exist,
|
||||
/// the value will be an empty string. Please note that the key is case-sensitive.
|
||||
/// Furthermore, the keys are in the format "root::key". That means that
|
||||
/// the keys are hierarchical and separated by "::".
|
||||
/// </remarks>
|
||||
/// <param name="key">The key to use to get the text.</param>
|
||||
/// <param name="value">The desired text.</param>
|
||||
/// <returns>True if the key exists, false otherwise.</returns>
|
||||
public bool TryGetText(string key, out string value)
|
||||
{
|
||||
if (this.content.TryGetValue(key, out value!))
|
||||
return true;
|
||||
|
||||
if(this.baseLanguage is not null && this.baseLanguage.TryGetText(key, out value))
|
||||
return true;
|
||||
|
||||
value = string.Empty;
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user