Added the culture setting entries
This commit is contained in:
4 files changed
+68
No files matched your search
@@ -150,8 +150,63 @@ public sealed partial class Setting : UserControl
|
||||
return new Setting(settingData);
|
||||
}
|
||||
|
||||
private static IEnumerable<Task<Setting>> ShowCultureSettingsAsync()
|
||||
{
|
||||
var isFirstCulture = true; // We need this flag to distinguish the first task from the others.
|
||||
var numberOfCultures = int.MaxValue; // There is always at least one culture, which is the default culture. We update this value later, out of the tasks.
|
||||
while (numberOfCultures > 0)
|
||||
{
|
||||
var innerLoopIndex = numberOfCultures; // needed to avoid closure issues.
|
||||
yield return Task.Run(async () =>
|
||||
{
|
||||
var localCultureIndex = innerLoopIndex;
|
||||
|
||||
// Get the total number of cultures. We cannot do this in the outer loop,
|
||||
// because we cannot await there. The AppSettings is caching the answer, though.
|
||||
var numberCultures = await AppSettings.GetNumberCultures();
|
||||
|
||||
// Update the number of cultures in the outer loop for the first call:
|
||||
if(isFirstCulture)
|
||||
{
|
||||
localCultureIndex = numberCultures;
|
||||
numberOfCultures = numberCultures;
|
||||
isFirstCulture = false;
|
||||
}
|
||||
|
||||
// Get the current culture code:
|
||||
var currentCultureCode = await AppSettings.GetCultureCode(localCultureIndex);
|
||||
|
||||
// Construct the setting:
|
||||
return new Setting(new()
|
||||
{
|
||||
Icon = Icons.icons8_chat_bubble_512,
|
||||
SettingName = () => $"{localCultureIndex}. Culture",
|
||||
SettingExplanation = () => "The culture according to RFC 4646: First comes the ISO 639-1 language code in lower case, followed by a hyphen, followed by the ISO 3166-1 alpha-2 country code in upper case. Example: en-US for English in the USA, de-DE for German in Germany.",
|
||||
SetupDataControl = () =>
|
||||
{
|
||||
var textbox = new TextBox();
|
||||
textbox.Text = currentCultureCode;
|
||||
textbox.TextChanged += async (sender, args) =>
|
||||
{
|
||||
await AppSettings.SetCultureCode(localCultureIndex, textbox.Text);
|
||||
};
|
||||
textbox.Dock = DockStyle.Fill;
|
||||
return textbox;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
numberOfCultures--;
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<Task<Setting>> GetAllSettings()
|
||||
{
|
||||
foreach (var setting in ShowCultureSettingsAsync())
|
||||
{
|
||||
yield return setting;
|
||||
}
|
||||
|
||||
yield return ShowDeepLActionSettingAsync();
|
||||
yield return ShowDeepLAPIKeySettingAsync();
|
||||
yield return ShowDeepLModeSettingAsync();
|
||||
|
||||
Reference in new issue
Block a user