Added the culture setting entries

This commit is contained in:
Thorsten Sommer 2022-07-31 21:19:54 +02:00
parent a47b18b7a8
commit fa112de26d
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
4 changed files with 68 additions and 0 deletions

View File

@ -150,8 +150,63 @@ public sealed partial class Setting : UserControl
return new Setting(settingData); 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() public static IEnumerable<Task<Setting>> GetAllSettings()
{ {
foreach (var setting in ShowCultureSettingsAsync())
{
yield return setting;
}
yield return ShowDeepLActionSettingAsync(); yield return ShowDeepLActionSettingAsync();
yield return ShowDeepLAPIKeySettingAsync(); yield return ShowDeepLAPIKeySettingAsync();
yield return ShowDeepLModeSettingAsync(); yield return ShowDeepLModeSettingAsync();

View File

@ -120,6 +120,16 @@ namespace UI_WinForms.Resources {
} }
} }
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap icons8_chat_bubble_512 {
get {
object obj = ResourceManager.GetObject("icons8_chat_bubble_512", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary> /// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap. /// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary> /// </summary>

View File

@ -136,6 +136,9 @@
<data name="icons8_cancel_512" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="icons8_cancel_512" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>icons8-cancel-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>icons8-cancel-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="icons8_chat_bubble_512" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>icons8-chat-bubble-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8_collectibles_512" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="icons8_collectibles_512" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>icons8-collectibles-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>icons8-collectibles-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB