mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 07:59:47 +00:00
Added an option for logging of unknown translation keys
This commit is contained in:
parent
dc427afdbd
commit
022cc9d68d
@ -16,8 +16,9 @@ public interface ILanguagePlugin
|
||||
/// </remarks>
|
||||
/// <param name="key">The key to use to get the text.</param>
|
||||
/// <param name="value">The desired text.</param>
|
||||
/// <param name="logWarning">When true, a warning will be logged if the key does not exist.</param>
|
||||
/// <returns>True if the key exists, false otherwise.</returns>
|
||||
public bool TryGetText(string key, out string value);
|
||||
public bool TryGetText(string key, out string value, bool logWarning = false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the text from the language plugin.
|
||||
|
@ -12,7 +12,7 @@ public sealed class NoPluginLanguage : PluginBase, ILanguagePlugin
|
||||
|
||||
#region Implementation of ILanguagePlugin
|
||||
|
||||
public bool TryGetText(string key, out string value)
|
||||
public bool TryGetText(string key, out string value, bool logWarning = false)
|
||||
{
|
||||
value = string.Empty;
|
||||
return true;
|
||||
|
@ -4,6 +4,8 @@ namespace AIStudio.Tools.PluginSystem;
|
||||
|
||||
public sealed class PluginLanguage : PluginBase, ILanguagePlugin
|
||||
{
|
||||
private static readonly ILogger<PluginLanguage> LOGGER = Program.LOGGER_FACTORY.CreateLogger<PluginLanguage>();
|
||||
|
||||
private readonly Dictionary<string, string> content = [];
|
||||
private readonly List<ILanguagePlugin> otherLanguagePlugins = [];
|
||||
private readonly string langCultureTag;
|
||||
@ -132,8 +134,9 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
|
||||
/// </remarks>
|
||||
/// <param name="key">The key to use to get the text.</param>
|
||||
/// <param name="value">The desired text.</param>
|
||||
/// <param name="logWarning">When true, a warning will be logged if the key does not exist.</param>
|
||||
/// <returns>True if the key exists, false otherwise.</returns>
|
||||
public bool TryGetText(string key, out string value)
|
||||
public bool TryGetText(string key, out string value, bool logWarning = false)
|
||||
{
|
||||
// First, we check if the key is part of the main language pack:
|
||||
if (this.content.TryGetValue(key, out value!))
|
||||
@ -150,6 +153,9 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
|
||||
if(this.baseLanguage is not null && this.baseLanguage.TryGetText(key, out value))
|
||||
return true;
|
||||
|
||||
if(logWarning)
|
||||
LOGGER.LogWarning($"Missing translation key '{key}'.");
|
||||
|
||||
value = string.Empty;
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user