AI-Studio/app/MindWork AI Studio/Tools/PluginSystem/PluginLanguage.cs
Thorsten Sommer b632854cd4
Some checks are pending
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Build app (linux-arm64) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Start the plugin system (#372)
2025-03-29 18:40:17 +01:00

48 lines
1.8 KiB
C#

using Lua;
namespace AIStudio.Tools.PluginSystem;
public sealed class PluginLanguage : PluginBase, ILanguagePlugin
{
private readonly Dictionary<string, string> content = [];
private ILanguagePlugin? baseLanguage;
public PluginLanguage(bool isInternal, LuaState state, PluginType type) : base(isInternal, 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;
}
}