Add LangName property to language plugin interface and implementation

This commit is contained in:
Thorsten Sommer 2025-04-12 11:10:20 +02:00
parent 445fc579ac
commit 7f6190a883
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
4 changed files with 40 additions and 0 deletions

View File

@ -44,6 +44,9 @@ DEPRECATION_MESSAGE = ""
-- code followed by the ISO 3166-1 country code: -- code followed by the ISO 3166-1 country code:
IETF_TAG = "de-DE" IETF_TAG = "de-DE"
-- The language name in the user's language:
LANG_NAME = "Deutsch (Deutschland)"
UI_TEXT_CONTENT = { UI_TEXT_CONTENT = {
HOME = CONTENT_HOME, HOME = CONTENT_HOME,
} }

View File

@ -44,6 +44,9 @@ DEPRECATION_MESSAGE = ""
-- code followed by the ISO 3166-1 country code: -- code followed by the ISO 3166-1 country code:
IETF_TAG = "en-US" IETF_TAG = "en-US"
-- The language name in the user's language:
LANG_NAME = "English (United States)"
UI_TEXT_CONTENT = { UI_TEXT_CONTENT = {
HOME = CONTENT_HOME, HOME = CONTENT_HOME,
} }

View File

@ -23,4 +23,9 @@ public interface ILanguagePlugin
/// Gets the IETF tag of the language plugin. /// Gets the IETF tag of the language plugin.
/// </summary> /// </summary>
public string IETFTag { get; } public string IETFTag { get; }
/// <summary>
/// Gets the name of the language.
/// </summary>
public string LangName { get; }
} }

View File

@ -7,6 +7,7 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
private readonly Dictionary<string, string> content = []; private readonly Dictionary<string, string> content = [];
private readonly List<ILanguagePlugin> otherLanguagePlugins = []; private readonly List<ILanguagePlugin> otherLanguagePlugins = [];
private readonly string langCultureTag; private readonly string langCultureTag;
private readonly string langName;
private ILanguagePlugin? baseLanguage; private ILanguagePlugin? baseLanguage;
@ -15,6 +16,9 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
if(!this.TryInitIETFTag(out var issue, out this.langCultureTag)) if(!this.TryInitIETFTag(out var issue, out this.langCultureTag))
this.pluginIssues.Add(issue); this.pluginIssues.Add(issue);
if(!this.TryInitLangName(out issue, out this.langName))
this.pluginIssues.Add(issue);
if (this.TryInitUITextContent(out issue, out var readContent)) if (this.TryInitUITextContent(out issue, out var readContent))
this.content = readContent; this.content = readContent;
else else
@ -127,7 +131,32 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
message = string.Empty; message = string.Empty;
return true; return true;
} }
private bool TryInitLangName(out string message, out string readLangName)
{
if (!this.state.Environment["LANG_NAME"].TryRead(out readLangName))
{
message = "The field LANG_NAME does not exist or is not a valid string.";
readLangName = string.Empty;
return false;
}
if (string.IsNullOrWhiteSpace(readLangName))
{
message = "The field LANG_NAME is empty. Use a valid language name.";
readLangName = string.Empty;
return false;
}
message = string.Empty;
return true;
}
/// <inheritdoc /> /// <inheritdoc />
public string IETFTag => this.langCultureTag; public string IETFTag => this.langCultureTag;
/// <inheritdoc />
public string LangName => this.langName;
#endregion
} }