Fix for translate merge lines

This commit is contained in:
Nikolaj Olsson 2020-06-12 20:31:13 +02:00
parent 52e632c64d
commit 945bd2e9fd
2 changed files with 10 additions and 7 deletions

View File

@ -197,7 +197,7 @@ namespace Nikse.SubtitleEdit.Core.Translate
var response = request.GetResponse(); var response = request.GetResponse();
var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd(); string content = reader.ReadToEnd();
var skipCount = 0;
var resultList = new List<string>(); var resultList = new List<string>();
var parser = new JsonParser(); var parser = new JsonParser();
var x = (Dictionary<string, object>)parser.Parse(content); var x = (Dictionary<string, object>)parser.Parse(content);
@ -221,12 +221,12 @@ namespace Nikse.SubtitleEdit.Core.Translate
translatedText = Regex.Unescape(translatedText); translatedText = Regex.Unescape(translatedText);
translatedText = string.Join(Environment.NewLine, translatedText.SplitToLines()); translatedText = string.Join(Environment.NewLine, translatedText.SplitToLines());
translatedText = TranslationHelper.PostTranslate(translatedText, targetLanguage); translatedText = TranslationHelper.PostTranslate(translatedText, targetLanguage);
if (resultList.Count < formatList.Count) if (resultList.Count - skipCount < formatList.Count)
{ {
translatedText = formatList[resultList.Count].ReAddFormatting(translatedText, out nextText); translatedText = formatList[resultList.Count - skipCount].ReAddFormatting(translatedText, out nextText);
if (nextText == null) if (nextText == null)
{ {
translatedText = formatList[resultList.Count].ReBreak(translatedText, targetLanguage); translatedText = formatList[resultList.Count - skipCount].ReBreak(translatedText, targetLanguage);
} }
} }
@ -235,6 +235,7 @@ namespace Nikse.SubtitleEdit.Core.Translate
if (nextText != null) if (nextText != null)
{ {
resultList.Add(nextText); resultList.Add(nextText);
skipCount++;
} }
} }
} }

View File

@ -155,6 +155,7 @@ namespace Nikse.SubtitleEdit.Core.Translate
var results = new List<string>(); var results = new List<string>();
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
var skipCount = 0;
using (var streamReader = new StreamReader(httpResponse.GetResponseStream() ?? throw new InvalidOperationException())) using (var streamReader = new StreamReader(httpResponse.GetResponseStream() ?? throw new InvalidOperationException()))
{ {
var result = streamReader.ReadToEnd(); var result = streamReader.ReadToEnd();
@ -171,13 +172,13 @@ namespace Nikse.SubtitleEdit.Core.Translate
var res = (string)textDics["text"]; var res = (string)textDics["text"];
string nextText = null; string nextText = null;
if (formatList.Count > results.Count) if (formatList.Count > results.Count - skipCount)
{ {
res = formatList[results.Count].ReAddFormatting(res, out nextText); res = formatList[results.Count - skipCount].ReAddFormatting(res, out nextText);
if (nextText == null) if (nextText == null)
{ {
res = formatList[results.Count].ReBreak(res, targetLanguage); res = formatList[results.Count - skipCount].ReBreak(res, targetLanguage);
} }
} }
@ -188,6 +189,7 @@ namespace Nikse.SubtitleEdit.Core.Translate
if (nextText != null) if (nextText != null)
{ {
results.Add(nextText); results.Add(nextText);
skipCount++;
} }
} }
} }