Added support for additional language plugins (#381)
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

This commit is contained in:
Thorsten Sommer 2025-04-03 10:34:09 +02:00 committed by GitHub
parent 158252dc34
commit ceefc0114b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,7 @@ namespace AIStudio.Tools.PluginSystem;
public sealed class PluginLanguage : PluginBase, ILanguagePlugin
{
private readonly Dictionary<string, string> content = [];
private readonly List<ILanguagePlugin> otherLanguagePlugins = [];
private ILanguagePlugin? baseLanguage;
@ -22,6 +23,16 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
/// <param name="baseLanguagePlugin">The base language plugin to use.</param>
public void SetBaseLanguage(ILanguagePlugin baseLanguagePlugin) => this.baseLanguage = baseLanguagePlugin;
/// <summary>
/// Add another language plugin. This plugin will be used to fill in missing keys.
/// </summary>
/// <remarks>
/// Use this method to add (i.e., register) an assistant plugin as a language plugin.
/// This is necessary because the assistant plugins need to serve their own texts.
/// </remarks>
/// <param name="languagePlugin">The language plugin to add.</param>
public void AddOtherLanguagePlugin(ILanguagePlugin languagePlugin) => this.otherLanguagePlugins.Add(languagePlugin);
/// <summary>
/// Tries to get a text from the language plugin.
/// </summary>
@ -36,9 +47,18 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
/// <returns>True if the key exists, false otherwise.</returns>
public bool TryGetText(string key, out string value)
{
// First, we check if the key is part of the main language pack:
if (this.content.TryGetValue(key, out value!))
return true;
// Second, we check if the key is part of the other language packs, such as the assistant plugins:
foreach (var otherLanguagePlugin in this.otherLanguagePlugins)
if(otherLanguagePlugin.TryGetText(key, out value))
return true;
// Finally, we check if the key is part of the base language pack. This is the case,
// when a language plugin does not cover all keys. In this case, the base language plugin
// will be used to fill in the missing keys:
if(this.baseLanguage is not null && this.baseLanguage.TryGetText(key, out value))
return true;