Add German localization (#430)
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 }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb 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 / 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 authored and GitHub committed 2025-04-27 16:13:15 +02:00
1 parent 2494ee2294
commit 47b6a89685
44 files changed
+3394 -262

No files matched your search

@@ -18,4 +18,24 @@ public interface ILang
/// <param name="fallbackEN">The fallback text in English (US).</param>
/// <returns>The text from the language plugin or the fallback text.</returns>
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,17 @@ public static class ILangExtensions
{
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 ns = $"{type.Namespace!}::{type.Name}".ToUpperInvariant().Replace(".", "::");
typeName ??= type.Name;
typeNamespace ??= type.Namespace!;
// When the type's name ends with `1 or 2`, etc. (i.e., generic classes), remove it:
if(typeName.Contains("`"))
typeName = typeName[..typeName.IndexOf('`')];
var ns = $"{typeNamespace}::{typeName}".ToUpperInvariant().Replace(".", "::");
var key = $"root::{ns}::T{fallbackEN.ToFNV32()}";
if(plugin is NoPluginLanguage)
@@ -22,15 +22,23 @@ public static partial class PluginFactory
HOT_RELOAD_WATCHER.Filter = "*.lua";
HOT_RELOAD_WATCHER.Changed += async (_, args) =>
{
var changeType = args.ChangeType.ToString().ToLowerInvariant();
if (!await HOT_RELOAD_SEMAPHORE.WaitAsync(0))
{
LOG.LogInformation($"File changed ({args.ChangeType}): {args.FullPath}. Already processing another change.");
LOG.LogInformation($"File changed ({changeType}): {args.FullPath}. Already processing another change.");
return;
}
LOG.LogInformation($"File changed ({args.ChangeType}): {args.FullPath}. Reloading plugins...");
await LoadAll();
await messageBus.SendMessage<bool>(null, Event.PLUGINS_RELOADED);
try
{
LOG.LogInformation($"File changed ({changeType}): {args.FullPath}. Reloading plugins...");
await LoadAll();
await messageBus.SendMessage<bool>(null, Event.PLUGINS_RELOADED);
}
finally
{
HOT_RELOAD_SEMAPHORE.Release();
}
};
HOT_RELOAD_WATCHER.EnableRaisingEvents = true;
@@ -55,39 +55,54 @@ public static partial class PluginFactory
var pluginMainFiles = Directory.EnumerateFiles(PLUGINS_ROOT, "plugin.lua", SearchOption.AllDirectories);
foreach (var pluginMainFile in pluginMainFiles)
{
if (cancellationToken.IsCancellationRequested)
break;
LOG.LogInformation($"Try to load plugin: {pluginMainFile}");
var code = await File.ReadAllTextAsync(pluginMainFile, Encoding.UTF8, cancellationToken);
var pluginPath = Path.GetDirectoryName(pluginMainFile)!;
var plugin = await Load(pluginPath, code, cancellationToken);
switch (plugin)
try
{
case NoPlugin noPlugin when noPlugin.Issues.Any():
LOG.LogError($"Was not able to load plugin: '{pluginMainFile}'. Reason: {noPlugin.Issues.First()}");
continue;
case NoPlugin:
LOG.LogError($"Was not able to load plugin: '{pluginMainFile}'. Reason: Unknown.");
continue;
case { IsValid: false }:
LOG.LogError($"Was not able to load plugin '{pluginMainFile}', because the Lua code is not a valid AI Studio plugin. There are {plugin.Issues.Count()} issues to fix. First issue is: {plugin.Issues.FirstOrDefault()}");
#if DEBUG
foreach (var pluginIssue in plugin.Issues)
LOG.LogError($"Plugin issue: {pluginIssue}");
#endif
continue;
case { IsMaintained: false }:
LOG.LogWarning($"The plugin '{pluginMainFile}' is not maintained anymore. Please consider to disable it.");
if (cancellationToken.IsCancellationRequested)
break;
}
LOG.LogInformation($"Successfully loaded plugin: '{pluginMainFile}' (Id='{plugin.Id}', Type='{plugin.Type}', Name='{plugin.Name}', Version='{plugin.Version}', Authors='{string.Join(", ", plugin.Authors)}')");
AVAILABLE_PLUGINS.Add(new PluginMetadata(plugin, pluginPath));
LOG.LogInformation($"Try to load plugin: {pluginMainFile}");
var fileInfo = new FileInfo(pluginMainFile);
string code;
await using(var fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using var reader = new StreamReader(fileStream, Encoding.UTF8);
code = await reader.ReadToEndAsync(cancellationToken);
}
var pluginPath = Path.GetDirectoryName(pluginMainFile)!;
var plugin = await Load(pluginPath, code, cancellationToken);
switch (plugin)
{
case NoPlugin noPlugin when noPlugin.Issues.Any():
LOG.LogError($"Was not able to load plugin: '{pluginMainFile}'. Reason: {noPlugin.Issues.First()}");
continue;
case NoPlugin:
LOG.LogError($"Was not able to load plugin: '{pluginMainFile}'. Reason: Unknown.");
continue;
case { IsValid: false }:
LOG.LogError($"Was not able to load plugin '{pluginMainFile}', because the Lua code is not a valid AI Studio plugin. There are {plugin.Issues.Count()} issues to fix. First issue is: {plugin.Issues.FirstOrDefault()}");
#if DEBUG
foreach (var pluginIssue in plugin.Issues)
LOG.LogError($"Plugin issue: {pluginIssue}");
#endif
continue;
case { IsMaintained: false }:
LOG.LogWarning($"The plugin '{pluginMainFile}' is not maintained anymore. Please consider to disable it.");
break;
}
LOG.LogInformation($"Successfully loaded plugin: '{pluginMainFile}' (Id='{plugin.Id}', Type='{plugin.Type}', Name='{plugin.Name}', Version='{plugin.Version}', Authors='{string.Join(", ", plugin.Authors)}')");
AVAILABLE_PLUGINS.Add(new PluginMetadata(plugin, pluginPath));
}
catch (Exception e)
{
LOG.LogError($"Was not able to load plugin '{pluginMainFile}'. Issue: {e.Message}");
LOG.LogDebug(e.StackTrace);
}
}
// Start or restart all plugins: