diff --git a/SubtitleEdit.sln.DotSettings b/SubtitleEdit.sln.DotSettings index aabb70e93..61e5bb287 100644 --- a/SubtitleEdit.sln.DotSettings +++ b/SubtitleEdit.sln.DotSettings @@ -25,6 +25,7 @@ True True True + True True True True diff --git a/src/ui/Forms/AudioToText/WhisperAudioToText.cs b/src/ui/Forms/AudioToText/WhisperAudioToText.cs index 569e42ef4..65fd1f78a 100644 --- a/src/ui/Forms/AudioToText/WhisperAudioToText.cs +++ b/src/ui/Forms/AudioToText/WhisperAudioToText.cs @@ -16,7 +16,6 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; -using static Nikse.SubtitleEdit.Forms.Options.Settings; using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox; namespace Nikse.SubtitleEdit.Forms.AudioToText diff --git a/src/ui/Forms/Translate/AutoTranslate.Designer.cs b/src/ui/Forms/Translate/AutoTranslate.Designer.cs index 033beca56..87c1fb49b 100644 --- a/src/ui/Forms/Translate/AutoTranslate.Designer.cs +++ b/src/ui/Forms/Translate/AutoTranslate.Designer.cs @@ -383,6 +383,7 @@ this.comboBoxSource.Size = new System.Drawing.Size(125, 23); this.comboBoxSource.TabIndex = 94; this.comboBoxSource.UsePopupWindow = false; + this.comboBoxSource.SelectedIndexChanged += new System.EventHandler(this.comboBoxSource_SelectedIndexChanged); // // comboBoxTarget // diff --git a/src/ui/Forms/Translate/AutoTranslate.cs b/src/ui/Forms/Translate/AutoTranslate.cs index da27b5a85..be68f7e8a 100644 --- a/src/ui/Forms/Translate/AutoTranslate.cs +++ b/src/ui/Forms/Translate/AutoTranslate.cs @@ -2,6 +2,7 @@ using Nikse.SubtitleEdit.Core.AutoTranslate; using Nikse.SubtitleEdit.Core.Common; using Nikse.SubtitleEdit.Core.Translate; +using Nikse.SubtitleEdit.Forms.Options; using Nikse.SubtitleEdit.Logic; using System; using System.Collections.Generic; @@ -576,13 +577,38 @@ namespace Nikse.SubtitleEdit.Forms.Translate } } - public static void FillComboWithLanguages(NikseComboBox comboBox, IEnumerable languages) + public static void FillComboWithLanguages(NikseComboBox comboBox, List languages) { comboBox.Items.Clear(); - foreach (var language in languages) + var languagesFilled = false; + + if (!string.IsNullOrEmpty(Configuration.Settings.General.DefaultLanguages)) { - comboBox.Items.Add(language); + var favorites = Utilities.GetSubtitleLanguageCultures(true).ToList(); + var languagesToAdd = new List(); + + foreach (var language in languages) + { + if (favorites.Any(p0 => p0.TwoLetterISOLanguageName == language.Code) || + favorites.Any(p1 => p1.ThreeLetterISOLanguageName == language.Code) || + (!string.IsNullOrWhiteSpace(language.Code) && favorites.Any(p2 => p2.TwoLetterISOLanguageName.StartsWith(language.Code, StringComparison.OrdinalIgnoreCase))) || + favorites.Any(p3 => p3.EnglishName.Contains(language.Name, StringComparison.OrdinalIgnoreCase)) || + favorites.Any(p4 => language.Name.Contains(p4.EnglishName, StringComparison.OrdinalIgnoreCase))) + { + languagesFilled = true; + languagesToAdd.Add(language); + } + } + + comboBox.Items.AddRange(languagesToAdd.OrderBy(p => p.Name).ToArray()); } + + if (!languagesFilled) + { + comboBox.Items.AddRange(languages.OrderBy(p => p.Name).ToArray()); + } + + comboBox.Items.Add(LanguageSettings.Current.General.ChangeLanguageFilter); } public static string EvaluateDefaultSourceLanguageCode(Encoding encoding, Subtitle subtitle, List sourceLanguages) @@ -1349,6 +1375,20 @@ namespace Nikse.SubtitleEdit.Forms.Translate private void comboBoxTarget_SelectedIndexChanged(object sender, EventArgs e) { + if (comboBoxTarget.SelectedIndex > 0 && comboBoxTarget.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; + } + } + + SetupLanguageSettings(); + return; + } + if (_autoTranslator.Name == DeepLTranslate.StaticName && comboBoxTarget.SelectedItem is TranslationPair target) { if (target.HasFormality == null || target.HasFormality == false) @@ -1402,5 +1442,23 @@ namespace Nikse.SubtitleEdit.Forms.Translate { translateCurrentLineToolStripMenuItem1_Click(null, null); } + + private void comboBoxSource_SelectedIndexChanged(object sender, EventArgs e) + { + if (comboBoxSource.SelectedIndex <= 0 || comboBoxSource.Text != LanguageSettings.Current.General.ChangeLanguageFilter) + { + return; + } + + using (var form = new DefaultLanguagesChooser(Configuration.Settings.General.DefaultLanguages)) + { + if (form.ShowDialog(this) == DialogResult.OK) + { + Configuration.Settings.General.DefaultLanguages = form.DefaultLanguages; + } + + SetupLanguageSettings(); + } + } } } diff --git a/src/ui/Forms/Translate/GoogleOrMicrosoftTranslate.Designer.cs b/src/ui/Forms/Translate/GoogleOrMicrosoftTranslate.Designer.cs index 77325e488..2490789e5 100644 --- a/src/ui/Forms/Translate/GoogleOrMicrosoftTranslate.Designer.cs +++ b/src/ui/Forms/Translate/GoogleOrMicrosoftTranslate.Designer.cs @@ -91,12 +91,27 @@ // // comboBoxFrom // + this.comboBoxFrom.BackColor = System.Drawing.SystemColors.Window; + this.comboBoxFrom.BackColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240))))); + this.comboBoxFrom.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(171)))), ((int)(((byte)(173)))), ((int)(((byte)(179))))); + this.comboBoxFrom.BorderColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(120)))), ((int)(((byte)(120))))); + this.comboBoxFrom.ButtonForeColor = System.Drawing.SystemColors.ControlText; + this.comboBoxFrom.ButtonForeColorDown = System.Drawing.Color.Orange; + this.comboBoxFrom.ButtonForeColorOver = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); + this.comboBoxFrom.DropDownHeight = 400; this.comboBoxFrom.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxFrom.DropDownWidth = 121; this.comboBoxFrom.FormattingEnabled = true; this.comboBoxFrom.Location = new System.Drawing.Point(256, 12); + this.comboBoxFrom.MaxLength = 32767; this.comboBoxFrom.Name = "comboBoxFrom"; + this.comboBoxFrom.SelectedIndex = -1; + this.comboBoxFrom.SelectedItem = null; + this.comboBoxFrom.SelectedText = ""; this.comboBoxFrom.Size = new System.Drawing.Size(121, 21); this.comboBoxFrom.TabIndex = 0; + this.comboBoxFrom.UsePopupWindow = false; + this.comboBoxFrom.SelectedIndexChanged += new System.EventHandler(this.comboBoxFrom_SelectedIndexChanged); // // buttonTranslate // @@ -119,12 +134,27 @@ // // comboBoxTo // + this.comboBoxTo.BackColor = System.Drawing.SystemColors.Window; + this.comboBoxTo.BackColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240))))); + this.comboBoxTo.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(171)))), ((int)(((byte)(173)))), ((int)(((byte)(179))))); + this.comboBoxTo.BorderColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(120)))), ((int)(((byte)(120))))); + this.comboBoxTo.ButtonForeColor = System.Drawing.SystemColors.ControlText; + this.comboBoxTo.ButtonForeColorDown = System.Drawing.Color.Orange; + this.comboBoxTo.ButtonForeColorOver = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); + this.comboBoxTo.DropDownHeight = 400; this.comboBoxTo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxTo.DropDownWidth = 121; this.comboBoxTo.FormattingEnabled = true; this.comboBoxTo.Location = new System.Drawing.Point(426, 12); + this.comboBoxTo.MaxLength = 32767; this.comboBoxTo.Name = "comboBoxTo"; + this.comboBoxTo.SelectedIndex = -1; + this.comboBoxTo.SelectedItem = null; + this.comboBoxTo.SelectedText = ""; this.comboBoxTo.Size = new System.Drawing.Size(121, 21); this.comboBoxTo.TabIndex = 1; + this.comboBoxTo.UsePopupWindow = false; + this.comboBoxTo.SelectedIndexChanged += new System.EventHandler(this.comboBoxTo_SelectedIndexChanged); // // labelFrom // @@ -137,6 +167,7 @@ // // textBoxSourceText // + this.textBoxSourceText.FocusedColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); this.textBoxSourceText.Location = new System.Drawing.Point(17, 71); this.textBoxSourceText.Multiline = true; this.textBoxSourceText.Name = "textBoxSourceText"; diff --git a/src/ui/Forms/Translate/GoogleOrMicrosoftTranslate.cs b/src/ui/Forms/Translate/GoogleOrMicrosoftTranslate.cs index 054190c2a..ac2b6e86d 100644 --- a/src/ui/Forms/Translate/GoogleOrMicrosoftTranslate.cs +++ b/src/ui/Forms/Translate/GoogleOrMicrosoftTranslate.cs @@ -5,6 +5,7 @@ using System.Windows.Forms; using Nikse.SubtitleEdit.Core.AutoTranslate; using Nikse.SubtitleEdit.Core.Common; using Nikse.SubtitleEdit.Core.Translate; +using Nikse.SubtitleEdit.Forms.Options; using Nikse.SubtitleEdit.Logic; namespace Nikse.SubtitleEdit.Forms.Translate @@ -47,8 +48,8 @@ namespace Nikse.SubtitleEdit.Forms.Translate var microsoftSourceLanguages = _microsoftTranslationService.GetSupportedSourceLanguages(); var microsoftTargetLanguages = _microsoftTranslationService.GetSupportedTargetLanguages(); - var targetLanguages = googleTargetLanguages.Intersect(microsoftTargetLanguages); - var fromLanguages = googleSourceLanguages.Intersect(microsoftSourceLanguages); + var targetLanguages = googleTargetLanguages.Intersect(microsoftTargetLanguages).ToList(); + var fromLanguages = googleSourceLanguages.Intersect(microsoftSourceLanguages).ToList(); AutoTranslate.FillComboWithLanguages(comboBoxFrom, fromLanguages); AutoTranslate.FillComboWithLanguages(comboBoxTo, targetLanguages); @@ -61,20 +62,22 @@ namespace Nikse.SubtitleEdit.Forms.Translate { _toLanguage = Configuration.Settings.Tools.GoogleTranslateLastTargetLanguage; _fromLanguage = defaultFromLanguage; - if (_toLanguage == defaultFromLanguage) + if (_toLanguage != defaultFromLanguage) { - foreach (var s in Utilities.GetDictionaryLanguages()) - { - string temp = s.Replace("[", string.Empty).Replace("]", string.Empty); - if (temp.Length > 4) - { - temp = temp.Substring(temp.Length - 5, 2).ToLowerInvariant(); + return; + } - if (temp != _toLanguage) - { - _toLanguage = temp; - break; - } + foreach (var s in Utilities.GetDictionaryLanguages()) + { + var temp = s.Replace("[", string.Empty).Replace("]", string.Empty); + if (temp.Length > 4) + { + temp = temp.Substring(temp.Length - 5, 2).ToLowerInvariant(); + + if (temp != _toLanguage) + { + _toLanguage = temp; + break; } } } @@ -104,7 +107,6 @@ namespace Nikse.SubtitleEdit.Forms.Translate Cursor = Cursors.WaitCursor; try { - buttonGoogle.Text = string.Empty; buttonMicrosoft.Text = string.Empty; @@ -155,5 +157,36 @@ namespace Nikse.SubtitleEdit.Forms.Translate } } + private void comboBoxFrom_SelectedIndexChanged(object sender, EventArgs e) + { + if (comboBoxFrom.SelectedIndex > 0 && comboBoxFrom.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; + } + } + + InitLanguageComboBoxes(); + } + } + + private void comboBoxTo_SelectedIndexChanged(object sender, EventArgs e) + { + if (comboBoxTo.SelectedIndex > 0 && comboBoxTo.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; + } + } + + InitLanguageComboBoxes(); + } + } } }