Read the user's preferred language from the OS (#382)
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 authored and GitHub committed 2025-04-03 14:25:45 +02:00
1 parent ceefc0114b
commit b456319434
10 files changed
+115 -1

No files matched your search

@@ -6,12 +6,16 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
{
private readonly Dictionary<string, string> content = [];
private readonly List<ILanguagePlugin> otherLanguagePlugins = [];
private readonly string langCultureTag;
private ILanguagePlugin? baseLanguage;
public PluginLanguage(bool isInternal, LuaState state, PluginType type) : base(isInternal, state, type)
{
if (this.TryInitUITextContent(out var issue, out var readContent))
if(!this.TryInitIETFTag(out var issue, out this.langCultureTag))
this.pluginIssues.Add(issue);
if (this.TryInitUITextContent(out issue, out var readContent))
this.content = readContent;
else
this.pluginIssues.Add(issue);
@@ -65,4 +69,62 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
value = string.Empty;
return false;
}
/// <summary>
/// Tries to initialize the IETF tag.
/// </summary>
/// <param name="message">The error message, when the IETF tag could not be read.</param>
/// <param name="readLangCultureTag">The read IETF tag.</param>
/// <returns>True, when the IETF tag could be read, false otherwise.</returns>
private bool TryInitIETFTag(out string message, out string readLangCultureTag)
{
if (!this.state.Environment["IETF_TAG"].TryRead(out readLangCultureTag))
{
message = "The field IETF_TAG does not exist or is not a valid string.";
readLangCultureTag = string.Empty;
return false;
}
if (string.IsNullOrWhiteSpace(readLangCultureTag))
{
message = "The field IETF_TAG is empty. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
readLangCultureTag = string.Empty;
return false;
}
if (readLangCultureTag.Length != 5)
{
message = "The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
readLangCultureTag = string.Empty;
return false;
}
if (readLangCultureTag[2] != '-')
{
message = "The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
readLangCultureTag = string.Empty;
return false;
}
// Check the first part consists of only lower case letters:
for (var i = 0; i < 2; i++)
if (!char.IsLower(readLangCultureTag[i]))
{
message = "The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
readLangCultureTag = string.Empty;
return false;
}
// Check the second part consists of only upper case letters:
for (var i = 3; i < 5; i++)
if (!char.IsUpper(readLangCultureTag[i]))
{
message = "The field IETF_TAG is not a valid IETF tag. Use a valid IETF tag like 'en-US'. The first part is the language, the second part is the country code.";
readLangCultureTag = string.Empty;
return false;
}
message = string.Empty;
return true;
}
}