diff --git a/Changelog.txt b/Changelog.txt
index 2cf411029..a50c8bc51 100644
--- a/Changelog.txt
+++ b/Changelog.txt
@@ -5,6 +5,8 @@
* UI layouts with support for TikTok/YouTube-shorts - thx leon/jmaraujouy/LearningJer
* Language filter (to minimize the long list of languages in combo boxes)
* Interjections are now language specific
+ * Translate via Facebook's NLLB (requires local API) - thx sharadagg
+ * Translate via LibreTranslate (requires local API) - thx AnonymousWebHacker
* Statistics for selected lines
* Shortcut "Set start time and go to next"
* IMPROVED:
diff --git a/SubtitleEdit.sln.DotSettings b/SubtitleEdit.sln.DotSettings
index 9ff8347ca..28c17e103 100644
--- a/SubtitleEdit.sln.DotSettings
+++ b/SubtitleEdit.sln.DotSettings
@@ -28,6 +28,7 @@
True
True
True
+ True
True
True
True
diff --git a/src/libse/AutoTranslate/LibreTranslate.cs b/src/libse/AutoTranslate/LibreTranslate.cs
new file mode 100644
index 000000000..71d6a902f
--- /dev/null
+++ b/src/libse/AutoTranslate/LibreTranslate.cs
@@ -0,0 +1,111 @@
+using Nikse.SubtitleEdit.Core.Common;
+using Nikse.SubtitleEdit.Core.Translate;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+using System.Text;
+using System.Threading.Tasks;
+using Nikse.SubtitleEdit.Core.Http;
+using Nikse.SubtitleEdit.Core.SubtitleFormats;
+using System.Net.Http.Headers;
+
+namespace Nikse.SubtitleEdit.Core.AutoTranslate
+{
+ public class LibreTranslate : IAutoTranslator
+ {
+ private HttpClient _httpClient;
+
+ public string Name { get; set; } = " LibreTranslate";
+ public string Url => "https://github.com/LibreTranslate/LibreTranslate";
+
+ public void Initialize()
+ {
+ _httpClient?.Dispose();
+ _httpClient = new HttpClient(); //DownloaderFactory.MakeHttpClient();
+ _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
+ _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json");
+ _httpClient.BaseAddress = new Uri(Configuration.Settings.Tools.AutoTranslateLibreUrl);
+ }
+
+ public List GetSupportedSourceLanguages()
+ {
+ return ListLanguages();
+ }
+
+ public List GetSupportedTargetLanguages()
+ {
+ return ListLanguages();
+ }
+
+ public async Task Translate(string text, string sourceLanguageCode, string targetLanguageCode)
+ {
+ var input = "{\"q\": \"" + Json.EncodeJsonText(text.Trim()) + "\", \"source\": \"" + sourceLanguageCode + "\", \"target\": \"" + targetLanguageCode + "\"}";
+ var content = new StringContent(input, Encoding.UTF8);
+ content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
+ var result = _httpClient.PostAsync("translate", content).Result;
+ result.EnsureSuccessStatusCode();
+ var bytes = await result.Content.ReadAsByteArrayAsync();
+ var json = Encoding.UTF8.GetString(bytes).Trim();
+
+ var parser = new SeJsonParser();
+ var resultText = parser.GetFirstObject(json, "translatedText");
+ if (resultText == null)
+ {
+ return string.Empty;
+ }
+
+ return Json.DecodeJsonText(resultText).Trim();
+ }
+
+ private static List ListLanguages()
+ {
+ var languageCodes = new List
+ {
+ "ar",
+ "az",
+ "cs",
+ "da",
+ "de",
+ "el",
+ "en",
+ "eo",
+ "es",
+ "fa",
+ "fi",
+ "fr",
+ "ga",
+ "he",
+ "hi",
+ "hu",
+ "id",
+ "it",
+ "ja",
+ "ko",
+ "nl",
+ "pl",
+ "pt",
+ "ru",
+ "ru",
+ "sk",
+ "sv",
+ "tr",
+ "uk",
+ "zh",
+ };
+
+ var result = new List();
+ var cultures = Utilities.GetSubtitleLanguageCultures(false).ToList();
+ foreach (var code in languageCodes)
+ {
+ var culture = cultures.FirstOrDefault(p=>p.TwoLetterISOLanguageName == code);
+ if (culture != null)
+ {
+ result.Add(new TranslationPair(culture.Name, code));
+ }
+ }
+
+ return result;
+ }
+ }
+}
diff --git a/src/libse/AutoTranslate/NoLanguageLeftBehindServe.cs b/src/libse/AutoTranslate/NoLanguageLeftBehindServe.cs
index a7ee5de0c..81dfb48dd 100644
--- a/src/libse/AutoTranslate/NoLanguageLeftBehindServe.cs
+++ b/src/libse/AutoTranslate/NoLanguageLeftBehindServe.cs
@@ -1,15 +1,13 @@
using Nikse.SubtitleEdit.Core.Common;
+using Nikse.SubtitleEdit.Core.Http;
+using Nikse.SubtitleEdit.Core.SubtitleFormats;
using Nikse.SubtitleEdit.Core.Translate;
using System;
using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
using System.Net.Http;
+using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
-using Nikse.SubtitleEdit.Core.Http;
-using Nikse.SubtitleEdit.Core.SubtitleFormats;
-using System.Net.Http.Headers;
namespace Nikse.SubtitleEdit.Core.AutoTranslate
{
@@ -45,7 +43,7 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
var sb = new StringBuilder();
foreach (var line in list)
{
- sb.Append("\"" + Json.EncodeJsonText(text) + "\", ");
+ sb.Append("\"" + Json.EncodeJsonText(line) + "\", ");
}
var src = sb.ToString().TrimEnd().TrimEnd(',').Trim();
diff --git a/src/libse/Common/Settings.cs b/src/libse/Common/Settings.cs
index b266dcd6b..2d7c4e599 100644
--- a/src/libse/Common/Settings.cs
+++ b/src/libse/Common/Settings.cs
@@ -156,6 +156,7 @@ namespace Nikse.SubtitleEdit.Core.Common
public string AutoTranslateLastUrl { get; set; }
public string AutoTranslateNllbApiUrl { get; set; }
public string AutoTranslateNllbServeUrl { get; set; }
+ public string AutoTranslateLibreUrl { get; set; }
public bool TranslateAllowSplit { get; set; }
public string TranslateLastService { get; set; }
public string TranslateMergeStrategy { get; set; }
@@ -499,6 +500,7 @@ namespace Nikse.SubtitleEdit.Core.Common
GoogleTranslateLastTargetLanguage = "en";
AutoTranslateNllbApiUrl = "https://winstxnhdw-nllb-api.hf.space/api/v2/";
AutoTranslateNllbServeUrl = "http://127.0.0.1:6060/";
+ AutoTranslateLibreUrl = "https://libretranslate.com/";
TranslateAllowSplit = true;
TranslateViaCopyPasteAutoCopyToClipboard = true;
TranslateViaCopyPasteMaxSize = 5000;
@@ -5084,6 +5086,12 @@ $HorzAlign = Center
settings.Tools.AutoTranslateNllbServeUrl = subNode.InnerText;
}
+ subNode = node.SelectSingleNode("AutoTranslateLibreUrl");
+ if (subNode != null)
+ {
+ settings.Tools.AutoTranslateLibreUrl = subNode.InnerText;
+ }
+
subNode = node.SelectSingleNode("TranslateAllowSplit");
if (subNode != null)
{
@@ -11342,6 +11350,7 @@ $HorzAlign = Center
textWriter.WriteElementString("AutoTranslateLastUrl", settings.Tools.AutoTranslateLastUrl);
textWriter.WriteElementString("AutoTranslateNllbApiUrl", settings.Tools.AutoTranslateNllbApiUrl);
textWriter.WriteElementString("AutoTranslateNllbServeUrl", settings.Tools.AutoTranslateNllbServeUrl);
+ textWriter.WriteElementString("AutoTranslateLibreUrl", settings.Tools.AutoTranslateLibreUrl);
textWriter.WriteElementString("TranslateAllowSplit", settings.Tools.TranslateAllowSplit.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("TranslateLastService", settings.Tools.TranslateLastService);
textWriter.WriteElementString("TranslateMergeStrategy", settings.Tools.TranslateMergeStrategy);
diff --git a/src/ui/Forms/Main.Designer.cs b/src/ui/Forms/Main.Designer.cs
index abd85533d..bd9325e88 100644
--- a/src/ui/Forms/Main.Designer.cs
+++ b/src/ui/Forms/Main.Designer.cs
@@ -40,9 +40,9 @@ namespace Nikse.SubtitleEdit.Forms
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Main));
- Nikse.SubtitleEdit.Core.Common.TimeCode timeCode4 = new Nikse.SubtitleEdit.Core.Common.TimeCode();
- Nikse.SubtitleEdit.Core.Common.TimeCode timeCode5 = new Nikse.SubtitleEdit.Core.Common.TimeCode();
- Nikse.SubtitleEdit.Core.Common.TimeCode timeCode6 = new Nikse.SubtitleEdit.Core.Common.TimeCode();
+ Nikse.SubtitleEdit.Core.Common.TimeCode timeCode1 = new Nikse.SubtitleEdit.Core.Common.TimeCode();
+ Nikse.SubtitleEdit.Core.Common.TimeCode timeCode2 = new Nikse.SubtitleEdit.Core.Common.TimeCode();
+ Nikse.SubtitleEdit.Core.Common.TimeCode timeCode3 = new Nikse.SubtitleEdit.Core.Common.TimeCode();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.labelStatus = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripSelected = new System.Windows.Forms.ToolStripStatusLabel();
@@ -259,6 +259,7 @@ namespace Nikse.SubtitleEdit.Forms
this.changeSpeedInPercentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemAutoTranslate = new System.Windows.Forms.ToolStripMenuItem();
this.translateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.autotranslateNLLBToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.autotranslateViaCopypasteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator26 = new System.Windows.Forms.ToolStripSeparator();
this.mergeSentencesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@@ -578,7 +579,6 @@ namespace Nikse.SubtitleEdit.Forms
this.timerOriginalTextUndo = new System.Windows.Forms.Timer(this.components);
this.contextMenuStripShowVideoControls = new System.Windows.Forms.ContextMenuStrip(this.components);
this.toolStripMenuItemShowVideoControls = new System.Windows.Forms.ToolStripMenuItem();
- this.autotranslateNLLBToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.statusStrip1.SuspendLayout();
this.toolStrip1.SuspendLayout();
this.menuStrip1.SuspendLayout();
@@ -2517,33 +2517,40 @@ namespace Nikse.SubtitleEdit.Forms
// translateToolStripMenuItem
//
this.translateToolStripMenuItem.Name = "translateToolStripMenuItem";
- this.translateToolStripMenuItem.Size = new System.Drawing.Size(238, 22);
+ this.translateToolStripMenuItem.Size = new System.Drawing.Size(282, 22);
this.translateToolStripMenuItem.Text = "Auto-translate...";
this.translateToolStripMenuItem.Click += new System.EventHandler(this.TranslateToolStripMenuItemClick);
//
+ // autotranslateNLLBToolStripMenuItem
+ //
+ this.autotranslateNLLBToolStripMenuItem.Name = "autotranslateNLLBToolStripMenuItem";
+ this.autotranslateNLLBToolStripMenuItem.Size = new System.Drawing.Size(282, 22);
+ this.autotranslateNLLBToolStripMenuItem.Text = "Auto-translate (NLLB/LibreTranslate)...";
+ this.autotranslateNLLBToolStripMenuItem.Click += new System.EventHandler(this.autotranslateNLLBToolStripMenuItem_Click);
+ //
// autotranslateViaCopypasteToolStripMenuItem
//
this.autotranslateViaCopypasteToolStripMenuItem.Name = "autotranslateViaCopypasteToolStripMenuItem";
- this.autotranslateViaCopypasteToolStripMenuItem.Size = new System.Drawing.Size(238, 22);
+ this.autotranslateViaCopypasteToolStripMenuItem.Size = new System.Drawing.Size(282, 22);
this.autotranslateViaCopypasteToolStripMenuItem.Text = "Auto-translate via copy-paste...";
this.autotranslateViaCopypasteToolStripMenuItem.Click += new System.EventHandler(this.AutotranslateViaCopypasteToolStripMenuItemClick);
//
// toolStripSeparator26
//
this.toolStripSeparator26.Name = "toolStripSeparator26";
- this.toolStripSeparator26.Size = new System.Drawing.Size(235, 6);
+ this.toolStripSeparator26.Size = new System.Drawing.Size(279, 6);
//
// mergeSentencesToolStripMenuItem
//
this.mergeSentencesToolStripMenuItem.Name = "mergeSentencesToolStripMenuItem";
- this.mergeSentencesToolStripMenuItem.Size = new System.Drawing.Size(238, 22);
+ this.mergeSentencesToolStripMenuItem.Size = new System.Drawing.Size(282, 22);
this.mergeSentencesToolStripMenuItem.Text = "Merge sentences...";
this.mergeSentencesToolStripMenuItem.Click += new System.EventHandler(this.MergeSentencesToolStripMenuItemClick);
//
// breaksplitLongLinesToolStripMenuItem
//
this.breaksplitLongLinesToolStripMenuItem.Name = "breaksplitLongLinesToolStripMenuItem";
- this.breaksplitLongLinesToolStripMenuItem.Size = new System.Drawing.Size(238, 22);
+ this.breaksplitLongLinesToolStripMenuItem.Size = new System.Drawing.Size(282, 22);
this.breaksplitLongLinesToolStripMenuItem.Text = "Break/split long lines...";
this.breaksplitLongLinesToolStripMenuItem.Click += new System.EventHandler(this.BreaksplitLongLinesToolStripMenuItemClick);
//
@@ -3871,14 +3878,14 @@ namespace Nikse.SubtitleEdit.Forms
this.timeUpDownVideoPosition.Size = new System.Drawing.Size(113, 23);
this.timeUpDownVideoPosition.TabIndex = 12;
this.timeUpDownVideoPosition.TabStop = false;
- timeCode4.Hours = 0;
- timeCode4.Milliseconds = 0;
- timeCode4.Minutes = 0;
- timeCode4.Seconds = 0;
- timeCode4.TimeSpan = System.TimeSpan.Parse("00:00:00");
- timeCode4.TotalMilliseconds = 0D;
- timeCode4.TotalSeconds = 0D;
- this.timeUpDownVideoPosition.TimeCode = timeCode4;
+ timeCode1.Hours = 0;
+ timeCode1.Milliseconds = 0;
+ timeCode1.Minutes = 0;
+ timeCode1.Seconds = 0;
+ timeCode1.TimeSpan = System.TimeSpan.Parse("00:00:00");
+ timeCode1.TotalMilliseconds = 0D;
+ timeCode1.TotalSeconds = 0D;
+ this.timeUpDownVideoPosition.TimeCode = timeCode1;
this.timeUpDownVideoPosition.UseVideoOffset = false;
//
// buttonGotoSub
@@ -4151,14 +4158,14 @@ namespace Nikse.SubtitleEdit.Forms
this.timeUpDownVideoPositionAdjust.Size = new System.Drawing.Size(113, 23);
this.timeUpDownVideoPositionAdjust.TabIndex = 13;
this.timeUpDownVideoPositionAdjust.TabStop = false;
- timeCode5.Hours = 0;
- timeCode5.Milliseconds = 0;
- timeCode5.Minutes = 0;
- timeCode5.Seconds = 0;
- timeCode5.TimeSpan = System.TimeSpan.Parse("00:00:00");
- timeCode5.TotalMilliseconds = 0D;
- timeCode5.TotalSeconds = 0D;
- this.timeUpDownVideoPositionAdjust.TimeCode = timeCode5;
+ timeCode2.Hours = 0;
+ timeCode2.Milliseconds = 0;
+ timeCode2.Minutes = 0;
+ timeCode2.Seconds = 0;
+ timeCode2.TimeSpan = System.TimeSpan.Parse("00:00:00");
+ timeCode2.TotalMilliseconds = 0D;
+ timeCode2.TotalSeconds = 0D;
+ this.timeUpDownVideoPositionAdjust.TimeCode = timeCode2;
this.timeUpDownVideoPositionAdjust.UseVideoOffset = false;
//
// buttonAdjustSetEndTime
@@ -5499,14 +5506,14 @@ namespace Nikse.SubtitleEdit.Forms
this.timeUpDownStartTime.Size = new System.Drawing.Size(113, 23);
this.timeUpDownStartTime.TabIndex = 0;
this.timeUpDownStartTime.TabStop = false;
- timeCode6.Hours = 0;
- timeCode6.Milliseconds = 0;
- timeCode6.Minutes = 0;
- timeCode6.Seconds = 0;
- timeCode6.TimeSpan = System.TimeSpan.Parse("00:00:00");
- timeCode6.TotalMilliseconds = 0D;
- timeCode6.TotalSeconds = 0D;
- this.timeUpDownStartTime.TimeCode = timeCode6;
+ timeCode3.Hours = 0;
+ timeCode3.Milliseconds = 0;
+ timeCode3.Minutes = 0;
+ timeCode3.Seconds = 0;
+ timeCode3.TimeSpan = System.TimeSpan.Parse("00:00:00");
+ timeCode3.TotalMilliseconds = 0D;
+ timeCode3.TotalSeconds = 0D;
+ this.timeUpDownStartTime.TimeCode = timeCode3;
this.timeUpDownStartTime.UseVideoOffset = false;
//
// numericUpDownDuration
@@ -5859,13 +5866,6 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripMenuItemShowVideoControls.Text = "Show video controls";
this.toolStripMenuItemShowVideoControls.Click += new System.EventHandler(this.ToolStripMenuItemShowVideoControlsClick);
//
- // autotranslateNLLBToolStripMenuItem
- //
- this.autotranslateNLLBToolStripMenuItem.Name = "autotranslateNLLBToolStripMenuItem";
- this.autotranslateNLLBToolStripMenuItem.Size = new System.Drawing.Size(238, 22);
- this.autotranslateNLLBToolStripMenuItem.Text = "Auto-translate (NLLB)...";
- this.autotranslateNLLBToolStripMenuItem.Click += new System.EventHandler(this.autotranslateNLLBToolStripMenuItem_Click);
- //
// Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
diff --git a/src/ui/Forms/Main.resx b/src/ui/Forms/Main.resx
index 65ad97d4b..484b4ad1b 100644
--- a/src/ui/Forms/Main.resx
+++ b/src/ui/Forms/Main.resx
@@ -687,9 +687,6 @@
652, 56
-
- 652, 56
-
iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
@@ -733,9 +730,9 @@
iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
- YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACJSURBVEhLYxjioPT6M4aKawVQHvEApAekFyfIvv6bofx6
+ YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACJSURBVEhLYxjioPT6M4aKawVQHvEApAekFyfIuv6bofx6
A5RHPADpAenFCbAZXHk1ACi2nqHi6n44BokhA5INrrpiwFBx/T9Q7DxYHILPg8VAcjBAssEgNsgQdACx
- DFXdqMFgMGowlDdqMCUG0yxLgwCowEEugEAFEsWFELGAoME0K+gHP2BgAADNshj2IuGeLgAAAABJRU5E
+ DFXdqMFgMGowlDdqMCUG0yxLgwCowEEugEAFEsWFELGAoME0K+gHP2BgAABTQhjW0rnwQAAAAABJRU5E
rkJggg==
@@ -772,12 +769,12 @@
981, 56
-
- 193, 17
-
668, 17
+
+ 193, 17
+
17, 95
diff --git a/src/ui/Forms/Translate/AutoTranslate.cs b/src/ui/Forms/Translate/AutoTranslate.cs
index 672c06ba6..c12926135 100644
--- a/src/ui/Forms/Translate/AutoTranslate.cs
+++ b/src/ui/Forms/Translate/AutoTranslate.cs
@@ -57,14 +57,15 @@ namespace Nikse.SubtitleEdit.Forms.Translate
Text = title;
}
+ _subtitle = new Subtitle(subtitle);
+ _encoding = encoding;
+
InitializeAutoTranslatorEngines();
nikseComboBoxUrl.UsePopupWindow = true;
labelPleaseWait.Visible = false;
progressBar1.Visible = false;
- _subtitle = new Subtitle(subtitle);
- _encoding = encoding;
if (selectedLines != null)
{
@@ -83,9 +84,6 @@ namespace Nikse.SubtitleEdit.Forms.Translate
subtitleListViewSource.Fill(_subtitle);
AutoTranslate_Resize(null, null);
-
- _autoTranslator = new NoLanguageLeftBehindApi();
- SetupLanguageSettings();
UpdateTranslation();
}
@@ -95,6 +93,7 @@ namespace Nikse.SubtitleEdit.Forms.Translate
{
new NoLanguageLeftBehindServe(),
new NoLanguageLeftBehindApi(),
+ new LibreTranslate(),
};
nikseComboBoxEngine.Items.Clear();
@@ -105,12 +104,14 @@ namespace Nikse.SubtitleEdit.Forms.Translate
var lastEngine = _autoTranslatorEngines.FirstOrDefault(p => p.Name == Configuration.Settings.Tools.AutoTranslateLastName);
if (lastEngine != null)
{
+ _autoTranslator = lastEngine;
nikseComboBoxEngine.SelectedIndex = _autoTranslatorEngines.IndexOf(lastEngine);
}
}
if (nikseComboBoxEngine.SelectedIndex < 0)
{
+ _autoTranslator = _autoTranslatorEngines[0];
nikseComboBoxEngine.SelectedIndex = 0;
}
@@ -122,9 +123,9 @@ namespace Nikse.SubtitleEdit.Forms.Translate
private void SetAutoTranslatorEngine()
{
- var engine = GetCurrentEngine();
- linkLabelPoweredBy.Text = string.Format(LanguageSettings.Current.GoogleTranslate.PoweredByX, engine.Name);
- var engineType = engine.GetType();
+ _autoTranslator = GetCurrentEngine();
+ linkLabelPoweredBy.Text = string.Format(LanguageSettings.Current.GoogleTranslate.PoweredByX, _autoTranslator.Name);
+ var engineType = _autoTranslator.GetType();
if (engineType == typeof(NoLanguageLeftBehindServe))
{
@@ -147,7 +148,17 @@ namespace Nikse.SubtitleEdit.Forms.Translate
return;
}
- throw new Exception($"Engine {engine.Name} not handled!");
+ if (engineType == typeof(LibreTranslate))
+ {
+ nikseComboBoxUrl.Items.Clear();
+ nikseComboBoxUrl.Items.Add("http://localhost:5000/");
+ nikseComboBoxUrl.SelectedIndex = 0;
+ nikseComboBoxUrl.Visible = true;
+ labelUrl.Visible = true;
+ return;
+ }
+
+ throw new Exception($"Engine {_autoTranslator.Name} not handled!");
}
private void SetAutoTranslatorUrl(string url)
@@ -163,7 +174,13 @@ namespace Nikse.SubtitleEdit.Forms.Translate
if (engineType == typeof(NoLanguageLeftBehindServe))
{
- Configuration.Settings.Tools.AutoTranslateNllbApiUrl = url;
+ Configuration.Settings.Tools.AutoTranslateNllbServeUrl = url;
+ return;
+ }
+
+ if (engineType == typeof(LibreTranslate))
+ {
+ Configuration.Settings.Tools.AutoTranslateLibreUrl = url;
return;
}
@@ -187,11 +204,17 @@ namespace Nikse.SubtitleEdit.Forms.Translate
var threeLetterLanguageCode = Iso639Dash2LanguageCode.GetThreeLetterCodeFromTwoLetterCode(languageIsoCode);
foreach (TranslationPair item in comboBox.Items)
{
- if (item.Code.StartsWith(threeLetterLanguageCode))
+ if (languageIsoCode.Length == 2 && item.Code == languageIsoCode)
{
comboBox.SelectedIndex = i;
return;
}
+ else if (item.Code.StartsWith(threeLetterLanguageCode) || item.Code == languageIsoCode)
+ {
+ comboBox.SelectedIndex = i;
+ return;
+ }
+
i++;
}
@@ -460,10 +483,20 @@ namespace Nikse.SubtitleEdit.Forms.Translate
UiUtil.ShowHelp("#translation");
}
}
+ else if (engineType == typeof(LibreTranslate))
+ {
+ var dr = MessageBox.Show($"{engine.Name} requires an API running locally!" + Environment.NewLine
+ + Environment.NewLine
+ + "Read more?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
+ if (dr == DialogResult.Yes)
+ {
+ UiUtil.ShowHelp("#translation");
+ }
+ }
}
else
{
- throw;
+ MessageBox.Show(exception.Message + Environment.NewLine + exception.StackTrace, MessageBoxIcon.Error);
}
}
}
@@ -749,6 +782,7 @@ namespace Nikse.SubtitleEdit.Forms.Translate
private void nikseComboBoxEngine_SelectedIndexChanged(object sender, EventArgs e)
{
SetAutoTranslatorEngine();
+ SetupLanguageSettings();
}
private void nikseComboBoxUrl_SelectedIndexChanged(object sender, EventArgs e)