Skip to content

Commit

Permalink
Minor auto-tr cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
niksedk committed Sep 6, 2024
1 parent 9c8e601 commit 4542409
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/ui/Forms/BatchConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1977,8 +1977,6 @@ public class TranslateResult

private TranslateResult RunAutoTranslate(Subtitle subtitle)
{
var engine = GetCurrentEngine();
engine.Initialize();
var translatedSubtitle = new Subtitle(subtitle);
foreach (var paragraph in translatedSubtitle.Paragraphs)
{
Expand All @@ -1995,7 +1993,7 @@ private TranslateResult RunAutoTranslate(Subtitle subtitle)
if (comboBoxSource.SelectedIndex == 0) // detect language
{
var language = LanguageAutoDetect.AutoDetectGoogleLanguageOrNull2(subtitle);
var tp = engine.GetSupportedSourceLanguages().FirstOrDefault(p => p.TwoLetterIsoLanguageName == language || p.Code == language);
var tp = _autoTranslator.GetSupportedSourceLanguages().FirstOrDefault(p => p.TwoLetterIsoLanguageName == language || p.Code == language);
if (tp != null)
{
source = tp;
Expand All @@ -2008,8 +2006,9 @@ private TranslateResult RunAutoTranslate(Subtitle subtitle)
}

var forceSingleLineMode =
engine.Name == NoLanguageLeftBehindApi.StaticName || // NLLB seems to miss some text...
engine.Name == NoLanguageLeftBehindServe.StaticName;
_autoTranslator.Name == NoLanguageLeftBehindApi.StaticName || // NLLB seems to miss some text...
_autoTranslator.Name == NoLanguageLeftBehindServe.StaticName || // NLLB seems to miss some text...
_autoTranslator.Name == OllamaTranslate.StaticName;

if (_autoTranslator.Name == OllamaTranslate.StaticName && !string.IsNullOrEmpty(nikseComboBoxTranslateModel.Text))
{
Expand All @@ -2023,7 +2022,7 @@ private TranslateResult RunAutoTranslate(Subtitle subtitle)
{
Application.DoEvents();

var task = Task.Run(async () => await MergeAndSplitHelper.MergeAndTranslateIfPossible(subtitle, translatedSubtitle, source, target, index, engine, forceSingleLineMode, CancellationToken.None).ConfigureAwait(false));
var task = Task.Run(async () => await MergeAndSplitHelper.MergeAndTranslateIfPossible(subtitle, translatedSubtitle, source, target, index, _autoTranslator, forceSingleLineMode, CancellationToken.None).ConfigureAwait(false));
task.Wait();

var linesMergedAndTranslated = task.Result;
Expand Down

0 comments on commit 4542409

Please sign in to comment.