From fa112de26d0636456ab815eb0cd20257a309c1fb Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 31 Jul 2022 21:19:54 +0200 Subject: [PATCH] Added the culture setting entries --- .../UI WinForms/Components/Setting.cs | 55 ++++++++++++++++++ .../UI WinForms/Resources/Icons.Designer.cs | 10 ++++ .../UI WinForms/Resources/Icons.resx | 3 + .../Resources/icons8-chat-bubble-512.png | Bin 0 -> 2239 bytes 4 files changed, 68 insertions(+) create mode 100644 I18N Commander/UI WinForms/Resources/icons8-chat-bubble-512.png diff --git a/I18N Commander/UI WinForms/Components/Setting.cs b/I18N Commander/UI WinForms/Components/Setting.cs index 6bff82f..87dc1a4 100644 --- a/I18N Commander/UI WinForms/Components/Setting.cs +++ b/I18N Commander/UI WinForms/Components/Setting.cs @@ -150,8 +150,63 @@ public sealed partial class Setting : UserControl return new Setting(settingData); } + private static IEnumerable> 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> GetAllSettings() { + foreach (var setting in ShowCultureSettingsAsync()) + { + yield return setting; + } + yield return ShowDeepLActionSettingAsync(); yield return ShowDeepLAPIKeySettingAsync(); yield return ShowDeepLModeSettingAsync(); diff --git a/I18N Commander/UI WinForms/Resources/Icons.Designer.cs b/I18N Commander/UI WinForms/Resources/Icons.Designer.cs index 6a7f135..7f3e9af 100644 --- a/I18N Commander/UI WinForms/Resources/Icons.Designer.cs +++ b/I18N Commander/UI WinForms/Resources/Icons.Designer.cs @@ -120,6 +120,16 @@ namespace UI_WinForms.Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap icons8_chat_bubble_512 { + get { + object obj = ResourceManager.GetObject("icons8_chat_bubble_512", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/I18N Commander/UI WinForms/Resources/Icons.resx b/I18N Commander/UI WinForms/Resources/Icons.resx index e23ca7c..6b0ceae 100644 --- a/I18N Commander/UI WinForms/Resources/Icons.resx +++ b/I18N Commander/UI WinForms/Resources/Icons.resx @@ -136,6 +136,9 @@ icons8-cancel-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + icons8-chat-bubble-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + icons8-collectibles-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/I18N Commander/UI WinForms/Resources/icons8-chat-bubble-512.png b/I18N Commander/UI WinForms/Resources/icons8-chat-bubble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