mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-26 05:02:36 +01:00
Better remember last auto-translate languages - thx vivodi :)
Fix #7761
This commit is contained in:
parent
7ab7ba279a
commit
2a4496c80e
@ -151,6 +151,7 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
public string GoogleApiV2Key { get; set; }
|
||||
public bool GoogleTranslateNoKeyWarningShow { get; set; }
|
||||
public int GoogleApiV1ChunkSize { get; set; }
|
||||
public string GoogleTranslateLastSourceLanguage { get; set; }
|
||||
public string GoogleTranslateLastTargetLanguage { get; set; }
|
||||
public string AutoTranslateLastName { get; set; }
|
||||
public string AutoTranslateLastUrl { get; set; }
|
||||
@ -5136,6 +5137,12 @@ $HorzAlign = Center
|
||||
settings.Tools.GoogleApiV1ChunkSize = Convert.ToInt32(subNode.InnerText, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
subNode = node.SelectSingleNode("GoogleTranslateLastSourceLanguage");
|
||||
if (subNode != null)
|
||||
{
|
||||
settings.Tools.GoogleTranslateLastSourceLanguage = subNode.InnerText;
|
||||
}
|
||||
|
||||
subNode = node.SelectSingleNode("GoogleTranslateLastTargetLanguage");
|
||||
if (subNode != null)
|
||||
{
|
||||
@ -11648,6 +11655,7 @@ $HorzAlign = Center
|
||||
textWriter.WriteElementString("GoogleApiV2Key", settings.Tools.GoogleApiV2Key);
|
||||
textWriter.WriteElementString("GoogleTranslateNoKeyWarningShow", settings.Tools.GoogleTranslateNoKeyWarningShow.ToString(CultureInfo.InvariantCulture));
|
||||
textWriter.WriteElementString("GoogleApiV1ChunkSize", settings.Tools.GoogleApiV1ChunkSize.ToString(CultureInfo.InvariantCulture));
|
||||
textWriter.WriteElementString("GoogleTranslateLastSourceLanguage", settings.Tools.GoogleTranslateLastSourceLanguage);
|
||||
textWriter.WriteElementString("GoogleTranslateLastTargetLanguage", settings.Tools.GoogleTranslateLastTargetLanguage);
|
||||
textWriter.WriteElementString("AutoTranslateLastName", settings.Tools.AutoTranslateLastName);
|
||||
textWriter.WriteElementString("AutoTranslateLastUrl", settings.Tools.AutoTranslateLastUrl);
|
||||
|
6
src/ui/Forms/Translate/AutoTranslate.Designer.cs
generated
6
src/ui/Forms/Translate/AutoTranslate.Designer.cs
generated
@ -322,13 +322,13 @@
|
||||
this.comboBoxSource.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSource.DropDownWidth = 140;
|
||||
this.comboBoxSource.FormattingEnabled = true;
|
||||
this.comboBoxSource.Location = new System.Drawing.Point(321, 25);
|
||||
this.comboBoxSource.Location = new System.Drawing.Point(318, 25);
|
||||
this.comboBoxSource.MaxLength = 32767;
|
||||
this.comboBoxSource.Name = "comboBoxSource";
|
||||
this.comboBoxSource.SelectedIndex = -1;
|
||||
this.comboBoxSource.SelectedItem = null;
|
||||
this.comboBoxSource.SelectedText = "";
|
||||
this.comboBoxSource.Size = new System.Drawing.Size(121, 23);
|
||||
this.comboBoxSource.Size = new System.Drawing.Size(125, 23);
|
||||
this.comboBoxSource.TabIndex = 94;
|
||||
this.comboBoxSource.UsePopupWindow = false;
|
||||
//
|
||||
@ -351,7 +351,7 @@
|
||||
this.comboBoxTarget.SelectedIndex = -1;
|
||||
this.comboBoxTarget.SelectedItem = null;
|
||||
this.comboBoxTarget.SelectedText = "";
|
||||
this.comboBoxTarget.Size = new System.Drawing.Size(121, 23);
|
||||
this.comboBoxTarget.Size = new System.Drawing.Size(125, 23);
|
||||
this.comboBoxTarget.TabIndex = 95;
|
||||
this.comboBoxTarget.UsePopupWindow = false;
|
||||
this.comboBoxTarget.SelectedIndexChanged += new System.EventHandler(this.comboBoxTarget_SelectedIndexChanged);
|
||||
|
@ -368,8 +368,9 @@ namespace Nikse.SubtitleEdit.Forms.Translate
|
||||
|
||||
private void SetupLanguageSettings()
|
||||
{
|
||||
FillComboWithLanguages(comboBoxSource, _autoTranslator.GetSupportedSourceLanguages());
|
||||
var sourceLanguageIsoCode = EvaluateDefaultSourceLanguageCode(_encoding, _subtitle);
|
||||
var sourceLanguages = _autoTranslator.GetSupportedSourceLanguages();
|
||||
FillComboWithLanguages(comboBoxSource, sourceLanguages);
|
||||
var sourceLanguageIsoCode = EvaluateDefaultSourceLanguageCode(_encoding, _subtitle, sourceLanguages);
|
||||
SelectLanguageCode(comboBoxSource, sourceLanguageIsoCode);
|
||||
|
||||
FillComboWithLanguages(comboBoxTarget, _autoTranslator.GetSupportedTargetLanguages());
|
||||
@ -381,6 +382,7 @@ namespace Nikse.SubtitleEdit.Forms.Translate
|
||||
{
|
||||
var i = 0;
|
||||
var threeLetterLanguageCode = Iso639Dash2LanguageCode.GetThreeLetterCodeFromTwoLetterCode(languageIsoCode);
|
||||
|
||||
foreach (TranslationPair item in comboBox.Items)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item.TwoLetterIsoLanguageName) && item.TwoLetterIsoLanguageName == languageIsoCode)
|
||||
@ -447,7 +449,7 @@ namespace Nikse.SubtitleEdit.Forms.Translate
|
||||
}
|
||||
}
|
||||
|
||||
public static string EvaluateDefaultSourceLanguageCode(Encoding encoding, Subtitle subtitle)
|
||||
public static string EvaluateDefaultSourceLanguageCode(Encoding encoding, Subtitle subtitle, List<TranslationPair> sourceLanguages)
|
||||
{
|
||||
var defaultSourceLanguageCode = LanguageAutoDetect.AutoDetectGoogleLanguage(encoding); // Guess language via encoding
|
||||
if (string.IsNullOrEmpty(defaultSourceLanguageCode))
|
||||
@ -455,6 +457,13 @@ namespace Nikse.SubtitleEdit.Forms.Translate
|
||||
defaultSourceLanguageCode = LanguageAutoDetect.AutoDetectGoogleLanguage(subtitle); // Guess language based on subtitle contents
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Configuration.Settings.Tools.GoogleTranslateLastSourceLanguage) &&
|
||||
Configuration.Settings.Tools.GoogleTranslateLastTargetLanguage.StartsWith(defaultSourceLanguageCode) &&
|
||||
sourceLanguages.Any(p=>p.Code == Configuration.Settings.Tools.GoogleTranslateLastSourceLanguage))
|
||||
{
|
||||
return Configuration.Settings.Tools.GoogleTranslateLastSourceLanguage;
|
||||
}
|
||||
|
||||
return defaultSourceLanguageCode;
|
||||
}
|
||||
|
||||
@ -607,6 +616,7 @@ namespace Nikse.SubtitleEdit.Forms.Translate
|
||||
TwoLetterIsoTarget = target.TwoLetterIsoLanguageName;
|
||||
var mergeErrorCount = 0;
|
||||
|
||||
Configuration.Settings.Tools.GoogleTranslateLastSourceLanguage = source.TwoLetterIsoLanguageName ?? source.Code;
|
||||
Configuration.Settings.Tools.GoogleTranslateLastTargetLanguage = target.TwoLetterIsoLanguageName ?? target.Code;
|
||||
try
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user