mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 03:02:35 +01:00
Use language-filter in auto-translate
This commit is contained in:
parent
b8da697419
commit
8854486351
@ -25,6 +25,7 @@
|
|||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bokm_00E5l/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bokm_00E5l/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bouten/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bouten/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Cuda/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Cuda/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=deepl/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=discardable/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=discardable/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Downloader/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Downloader/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ffmpeg/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ffmpeg/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
@ -16,7 +16,6 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using static Nikse.SubtitleEdit.Forms.Options.Settings;
|
|
||||||
using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox;
|
using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox;
|
||||||
|
|
||||||
namespace Nikse.SubtitleEdit.Forms.AudioToText
|
namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||||
|
1
src/ui/Forms/Translate/AutoTranslate.Designer.cs
generated
1
src/ui/Forms/Translate/AutoTranslate.Designer.cs
generated
@ -383,6 +383,7 @@
|
|||||||
this.comboBoxSource.Size = new System.Drawing.Size(125, 23);
|
this.comboBoxSource.Size = new System.Drawing.Size(125, 23);
|
||||||
this.comboBoxSource.TabIndex = 94;
|
this.comboBoxSource.TabIndex = 94;
|
||||||
this.comboBoxSource.UsePopupWindow = false;
|
this.comboBoxSource.UsePopupWindow = false;
|
||||||
|
this.comboBoxSource.SelectedIndexChanged += new System.EventHandler(this.comboBoxSource_SelectedIndexChanged);
|
||||||
//
|
//
|
||||||
// comboBoxTarget
|
// comboBoxTarget
|
||||||
//
|
//
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using Nikse.SubtitleEdit.Core.AutoTranslate;
|
using Nikse.SubtitleEdit.Core.AutoTranslate;
|
||||||
using Nikse.SubtitleEdit.Core.Common;
|
using Nikse.SubtitleEdit.Core.Common;
|
||||||
using Nikse.SubtitleEdit.Core.Translate;
|
using Nikse.SubtitleEdit.Core.Translate;
|
||||||
|
using Nikse.SubtitleEdit.Forms.Options;
|
||||||
using Nikse.SubtitleEdit.Logic;
|
using Nikse.SubtitleEdit.Logic;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -576,15 +577,40 @@ namespace Nikse.SubtitleEdit.Forms.Translate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FillComboWithLanguages(NikseComboBox comboBox, IEnumerable<TranslationPair> languages)
|
public static void FillComboWithLanguages(NikseComboBox comboBox, List<TranslationPair> languages)
|
||||||
{
|
{
|
||||||
comboBox.Items.Clear();
|
comboBox.Items.Clear();
|
||||||
|
var languagesFilled = false;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(Configuration.Settings.General.DefaultLanguages))
|
||||||
|
{
|
||||||
|
var favorites = Utilities.GetSubtitleLanguageCultures(true).ToList();
|
||||||
|
var languagesToAdd = new List<TranslationPair>();
|
||||||
|
|
||||||
foreach (var language in languages)
|
foreach (var language in languages)
|
||||||
{
|
{
|
||||||
comboBox.Items.Add(language);
|
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<object>());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!languagesFilled)
|
||||||
|
{
|
||||||
|
comboBox.Items.AddRange(languages.OrderBy(p => p.Name).ToArray<object>());
|
||||||
|
}
|
||||||
|
|
||||||
|
comboBox.Items.Add(LanguageSettings.Current.General.ChangeLanguageFilter);
|
||||||
|
}
|
||||||
|
|
||||||
public static string EvaluateDefaultSourceLanguageCode(Encoding encoding, Subtitle subtitle, List<TranslationPair> sourceLanguages)
|
public static string EvaluateDefaultSourceLanguageCode(Encoding encoding, Subtitle subtitle, List<TranslationPair> sourceLanguages)
|
||||||
{
|
{
|
||||||
var defaultSourceLanguageCode = LanguageAutoDetect.AutoDetectGoogleLanguage(encoding); // Guess language via encoding
|
var defaultSourceLanguageCode = LanguageAutoDetect.AutoDetectGoogleLanguage(encoding); // Guess language via encoding
|
||||||
@ -1349,6 +1375,20 @@ namespace Nikse.SubtitleEdit.Forms.Translate
|
|||||||
|
|
||||||
private void comboBoxTarget_SelectedIndexChanged(object sender, EventArgs e)
|
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 (_autoTranslator.Name == DeepLTranslate.StaticName && comboBoxTarget.SelectedItem is TranslationPair target)
|
||||||
{
|
{
|
||||||
if (target.HasFormality == null || target.HasFormality == false)
|
if (target.HasFormality == null || target.HasFormality == false)
|
||||||
@ -1402,5 +1442,23 @@ namespace Nikse.SubtitleEdit.Forms.Translate
|
|||||||
{
|
{
|
||||||
translateCurrentLineToolStripMenuItem1_Click(null, null);
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,12 +91,27 @@
|
|||||||
//
|
//
|
||||||
// comboBoxFrom
|
// 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.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.comboBoxFrom.DropDownWidth = 121;
|
||||||
this.comboBoxFrom.FormattingEnabled = true;
|
this.comboBoxFrom.FormattingEnabled = true;
|
||||||
this.comboBoxFrom.Location = new System.Drawing.Point(256, 12);
|
this.comboBoxFrom.Location = new System.Drawing.Point(256, 12);
|
||||||
|
this.comboBoxFrom.MaxLength = 32767;
|
||||||
this.comboBoxFrom.Name = "comboBoxFrom";
|
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.Size = new System.Drawing.Size(121, 21);
|
||||||
this.comboBoxFrom.TabIndex = 0;
|
this.comboBoxFrom.TabIndex = 0;
|
||||||
|
this.comboBoxFrom.UsePopupWindow = false;
|
||||||
|
this.comboBoxFrom.SelectedIndexChanged += new System.EventHandler(this.comboBoxFrom_SelectedIndexChanged);
|
||||||
//
|
//
|
||||||
// buttonTranslate
|
// buttonTranslate
|
||||||
//
|
//
|
||||||
@ -119,12 +134,27 @@
|
|||||||
//
|
//
|
||||||
// comboBoxTo
|
// 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.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.comboBoxTo.DropDownWidth = 121;
|
||||||
this.comboBoxTo.FormattingEnabled = true;
|
this.comboBoxTo.FormattingEnabled = true;
|
||||||
this.comboBoxTo.Location = new System.Drawing.Point(426, 12);
|
this.comboBoxTo.Location = new System.Drawing.Point(426, 12);
|
||||||
|
this.comboBoxTo.MaxLength = 32767;
|
||||||
this.comboBoxTo.Name = "comboBoxTo";
|
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.Size = new System.Drawing.Size(121, 21);
|
||||||
this.comboBoxTo.TabIndex = 1;
|
this.comboBoxTo.TabIndex = 1;
|
||||||
|
this.comboBoxTo.UsePopupWindow = false;
|
||||||
|
this.comboBoxTo.SelectedIndexChanged += new System.EventHandler(this.comboBoxTo_SelectedIndexChanged);
|
||||||
//
|
//
|
||||||
// labelFrom
|
// labelFrom
|
||||||
//
|
//
|
||||||
@ -137,6 +167,7 @@
|
|||||||
//
|
//
|
||||||
// textBoxSourceText
|
// 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.Location = new System.Drawing.Point(17, 71);
|
||||||
this.textBoxSourceText.Multiline = true;
|
this.textBoxSourceText.Multiline = true;
|
||||||
this.textBoxSourceText.Name = "textBoxSourceText";
|
this.textBoxSourceText.Name = "textBoxSourceText";
|
||||||
|
@ -5,6 +5,7 @@ using System.Windows.Forms;
|
|||||||
using Nikse.SubtitleEdit.Core.AutoTranslate;
|
using Nikse.SubtitleEdit.Core.AutoTranslate;
|
||||||
using Nikse.SubtitleEdit.Core.Common;
|
using Nikse.SubtitleEdit.Core.Common;
|
||||||
using Nikse.SubtitleEdit.Core.Translate;
|
using Nikse.SubtitleEdit.Core.Translate;
|
||||||
|
using Nikse.SubtitleEdit.Forms.Options;
|
||||||
using Nikse.SubtitleEdit.Logic;
|
using Nikse.SubtitleEdit.Logic;
|
||||||
|
|
||||||
namespace Nikse.SubtitleEdit.Forms.Translate
|
namespace Nikse.SubtitleEdit.Forms.Translate
|
||||||
@ -47,8 +48,8 @@ namespace Nikse.SubtitleEdit.Forms.Translate
|
|||||||
var microsoftSourceLanguages = _microsoftTranslationService.GetSupportedSourceLanguages();
|
var microsoftSourceLanguages = _microsoftTranslationService.GetSupportedSourceLanguages();
|
||||||
var microsoftTargetLanguages = _microsoftTranslationService.GetSupportedTargetLanguages();
|
var microsoftTargetLanguages = _microsoftTranslationService.GetSupportedTargetLanguages();
|
||||||
|
|
||||||
var targetLanguages = googleTargetLanguages.Intersect(microsoftTargetLanguages);
|
var targetLanguages = googleTargetLanguages.Intersect(microsoftTargetLanguages).ToList();
|
||||||
var fromLanguages = googleSourceLanguages.Intersect(microsoftSourceLanguages);
|
var fromLanguages = googleSourceLanguages.Intersect(microsoftSourceLanguages).ToList();
|
||||||
|
|
||||||
AutoTranslate.FillComboWithLanguages(comboBoxFrom, fromLanguages);
|
AutoTranslate.FillComboWithLanguages(comboBoxFrom, fromLanguages);
|
||||||
AutoTranslate.FillComboWithLanguages(comboBoxTo, targetLanguages);
|
AutoTranslate.FillComboWithLanguages(comboBoxTo, targetLanguages);
|
||||||
@ -61,11 +62,14 @@ namespace Nikse.SubtitleEdit.Forms.Translate
|
|||||||
{
|
{
|
||||||
_toLanguage = Configuration.Settings.Tools.GoogleTranslateLastTargetLanguage;
|
_toLanguage = Configuration.Settings.Tools.GoogleTranslateLastTargetLanguage;
|
||||||
_fromLanguage = defaultFromLanguage;
|
_fromLanguage = defaultFromLanguage;
|
||||||
if (_toLanguage == defaultFromLanguage)
|
if (_toLanguage != defaultFromLanguage)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var s in Utilities.GetDictionaryLanguages())
|
foreach (var s in Utilities.GetDictionaryLanguages())
|
||||||
{
|
{
|
||||||
string temp = s.Replace("[", string.Empty).Replace("]", string.Empty);
|
var temp = s.Replace("[", string.Empty).Replace("]", string.Empty);
|
||||||
if (temp.Length > 4)
|
if (temp.Length > 4)
|
||||||
{
|
{
|
||||||
temp = temp.Substring(temp.Length - 5, 2).ToLowerInvariant();
|
temp = temp.Substring(temp.Length - 5, 2).ToLowerInvariant();
|
||||||
@ -78,7 +82,6 @@ namespace Nikse.SubtitleEdit.Forms.Translate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal void Initialize(Paragraph paragraph)
|
internal void Initialize(Paragraph paragraph)
|
||||||
{
|
{
|
||||||
@ -104,7 +107,6 @@ namespace Nikse.SubtitleEdit.Forms.Translate
|
|||||||
Cursor = Cursors.WaitCursor;
|
Cursor = Cursors.WaitCursor;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
buttonGoogle.Text = string.Empty;
|
buttonGoogle.Text = string.Empty;
|
||||||
buttonMicrosoft.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user