From d7358b591032c75b5137117bc98f492e9a4d1dc3 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Tue, 28 May 2024 07:53:17 +0200 Subject: [PATCH] More language filter --- .../Forms/AudioToText/WhisperAudioToText.cs | 22 +++++++++---------- .../WhisperAudioToTextSelectedLines.cs | 21 ++++++++++++++---- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/ui/Forms/AudioToText/WhisperAudioToText.cs b/src/ui/Forms/AudioToText/WhisperAudioToText.cs index 65fd1f78a..c20dc5124 100644 --- a/src/ui/Forms/AudioToText/WhisperAudioToText.cs +++ b/src/ui/Forms/AudioToText/WhisperAudioToText.cs @@ -186,7 +186,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText private void Init() { - InitializeLanguageNames(); + InitializeLanguageNames(comboBoxLanguages); FillModels(comboBoxModels, string.Empty); @@ -1930,16 +1930,16 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText } } - InitializeLanguageNames(); + InitializeLanguageNames(comboBoxLanguages); return; } checkBoxTranslateToEnglish.Enabled = comboBoxLanguages.Text.ToLowerInvariant() != "english"; } - private void InitializeLanguageNames() + internal static void InitializeLanguageNames(NikseComboBox comboBox) { - comboBoxLanguages.Items.Clear(); + comboBox.Items.Clear(); var languagesFilled = false; @@ -1960,24 +1960,24 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText } } - comboBoxLanguages.Items.AddRange(languagesToAdd.OrderBy(p => p.Name).ToArray()); + comboBox.Items.AddRange(languagesToAdd.OrderBy(p => p.Name).ToArray()); var lang = languages.FirstOrDefault(p => p.Code == Configuration.Settings.Tools.WhisperLanguageCode); - comboBoxLanguages.Text = lang != null ? lang.ToString() : "English"; + comboBox.Text = lang != null ? lang.ToString() : "English"; } if (!languagesFilled) { - comboBoxLanguages.Items.AddRange(WhisperLanguage.Languages.OrderBy(p => p.Name).ToArray()); + comboBox.Items.AddRange(WhisperLanguage.Languages.OrderBy(p => p.Name).ToArray()); var lang = WhisperLanguage.Languages.FirstOrDefault(p => p.Code == Configuration.Settings.Tools.WhisperLanguageCode); - comboBoxLanguages.Text = lang != null ? lang.ToString() : "English"; + comboBox.Text = lang != null ? lang.ToString() : "English"; } - comboBoxLanguages.Items.Add(LanguageSettings.Current.General.ChangeLanguageFilter); + comboBox.Items.Add(LanguageSettings.Current.General.ChangeLanguageFilter); - if (string.IsNullOrEmpty(comboBoxLanguages.Text) && comboBoxLanguages.Items.Count > 0) + if (string.IsNullOrEmpty(comboBox.Text) && comboBox.Items.Count > 0) { - comboBoxLanguages.SelectedIndex = 0; + comboBox.SelectedIndex = 0; } } diff --git a/src/ui/Forms/AudioToText/WhisperAudioToTextSelectedLines.cs b/src/ui/Forms/AudioToText/WhisperAudioToTextSelectedLines.cs index 89a48b58f..1ee290d53 100644 --- a/src/ui/Forms/AudioToText/WhisperAudioToTextSelectedLines.cs +++ b/src/ui/Forms/AudioToText/WhisperAudioToTextSelectedLines.cs @@ -1,5 +1,6 @@ using Nikse.SubtitleEdit.Core.AudioToText; using Nikse.SubtitleEdit.Core.Common; +using Nikse.SubtitleEdit.Forms.Options; using Nikse.SubtitleEdit.Logic; using System; using System.Collections.Concurrent; @@ -82,10 +83,8 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText private void Init() { - comboBoxLanguages.Items.Clear(); - comboBoxLanguages.Items.AddRange(WhisperLanguage.Languages.OrderBy(p => p.Name).ToArray()); - var lang = WhisperLanguage.Languages.FirstOrDefault(p => p.Code == Configuration.Settings.Tools.WhisperLanguageCode); - comboBoxLanguages.Text = lang != null ? lang.ToString() : "English"; + WhisperAudioToText.InitializeLanguageNames(comboBoxLanguages); + WhisperAudioToText.FillModels(comboBoxModels, string.Empty); removeTemporaryFilesToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperDeleteTempFiles; @@ -467,6 +466,20 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText private void comboBoxLanguages_SelectedIndexChanged(object sender, EventArgs e) { + if (comboBoxLanguages.SelectedIndex > 0 && comboBoxLanguages.Text == LanguageSettings.Current.General.ChangeLanguageFilter) + { + using (var form = new DefaultLanguagesChooser(Configuration.Settings.General.DefaultLanguages)) + { + if (form.ShowDialog(this) == DialogResult.OK) + { + Configuration.Settings.General.DefaultLanguages = form.DefaultLanguages; + } + } + + WhisperAudioToText.InitializeLanguageNames(comboBoxLanguages); + return; + } + checkBoxTranslateToEnglish.Enabled = comboBoxLanguages.Text.ToLowerInvariant() != "english"; }