Added DeepL source culture
This commit is contained in:
parent
ba86c99ad5
commit
c07571c477
@ -150,6 +150,59 @@ public sealed partial class Setting : UserControl
|
|||||||
return new Setting(settingData);
|
return new Setting(settingData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal readonly record struct ComboBoxItem(string DisplayText, int CultureIndex)
|
||||||
|
{
|
||||||
|
public override string ToString() => this.DisplayText;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<Setting> ShowDeepLSourceCultureSettingAsync()
|
||||||
|
{
|
||||||
|
var currentSourceCultureIndex = await AppSettings.GetDeepLSourceCultureIndex();
|
||||||
|
|
||||||
|
// We load the corresponding culture for that index. As dropdown items, we show
|
||||||
|
// all other available cultures:
|
||||||
|
var allCultures = await AppSettings.GetCultureInfos();
|
||||||
|
var sourceCulture = allCultures.FirstOrDefault(n => n.Index == currentSourceCultureIndex);
|
||||||
|
|
||||||
|
// Attention: We have to store the culture's index, because the index is not
|
||||||
|
// continuous and can change when the user adds or removes a culture!
|
||||||
|
var settingData = new SettingUIData(
|
||||||
|
Icon: Icons.icons8_chat_bubble_512,
|
||||||
|
SettingName: () => "DeepL Source Culture",
|
||||||
|
SettingExplanation: () => "The source culture is used to translate the missing translations.",
|
||||||
|
SetupDataControl: () =>
|
||||||
|
{
|
||||||
|
var dropdown = new ComboBox();
|
||||||
|
var currentCultureDropdownIndex = 0;
|
||||||
|
for (var n = 0; n < allCultures.Count; n++)
|
||||||
|
{
|
||||||
|
var cultureInfo = allCultures[n];
|
||||||
|
if(cultureInfo.Index == currentSourceCultureIndex)
|
||||||
|
currentCultureDropdownIndex = n;
|
||||||
|
|
||||||
|
dropdown.Items.Add(new ComboBoxItem($"{cultureInfo.Index}.: {cultureInfo.Code}", cultureInfo.Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
dropdown.SelectedIndex = currentCultureDropdownIndex;
|
||||||
|
|
||||||
|
// Setup the change event handler:
|
||||||
|
dropdown.SelectedValueChanged += async (sender, args) =>
|
||||||
|
{
|
||||||
|
if(dropdown.SelectedItem is ComboBoxItem selectedItem)
|
||||||
|
await AppSettings.SetDeepLSourceCultureIndex(selectedItem.CultureIndex);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Apply the desired layout:
|
||||||
|
dropdown.Dock = DockStyle.Fill;
|
||||||
|
dropdown.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
|
||||||
|
return dropdown;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Setting(settingData);
|
||||||
|
}
|
||||||
|
|
||||||
private static IEnumerable<Task<Setting>> ShowCultureSettingsAsync()
|
private static IEnumerable<Task<Setting>> ShowCultureSettingsAsync()
|
||||||
{
|
{
|
||||||
var isFirstCulture = true; // We need this flag to distinguish the first task from the others.
|
var isFirstCulture = true; // We need this flag to distinguish the first task from the others.
|
||||||
@ -206,6 +259,7 @@ public sealed partial class Setting : UserControl
|
|||||||
|
|
||||||
public static IEnumerable<Task<Setting>> GetAllSettings()
|
public static IEnumerable<Task<Setting>> GetAllSettings()
|
||||||
{
|
{
|
||||||
|
yield return ShowDeepLSourceCultureSettingAsync();
|
||||||
foreach (var setting in ShowCultureSettingsAsync())
|
foreach (var setting in ShowCultureSettingsAsync())
|
||||||
{
|
{
|
||||||
yield return setting;
|
yield return setting;
|
||||||
|
Loading…
Reference in New Issue
Block a user