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-512.png new file mode 100644 index 0000000..2fa6102 Binary files /dev/null and b/I18N Commander/UI WinForms/Resources/icons8-chat-bubble-512.png differ