From a38e5fa408383e5ba38c8e7ff31af2411b9d4735 Mon Sep 17 00:00:00 2001 From: niksedk Date: Fri, 27 Jan 2023 23:10:36 +0100 Subject: [PATCH] Fix for recent translate commit --- src/libse/Translate/Formatting.cs | 29 +++++++++++++++++-- .../NextLineMergeTranslationProcessor.cs | 8 ++++- .../Translate/Service/GoogleTranslator1.cs | 6 +++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/libse/Translate/Formatting.cs b/src/libse/Translate/Formatting.cs index b51afe303..30e9ee02b 100644 --- a/src/libse/Translate/Formatting.cs +++ b/src/libse/Translate/Formatting.cs @@ -22,12 +22,15 @@ namespace Nikse.SubtitleEdit.Core.Translate private int BreakNumberOfLines { get; set; } private bool BreakSplitAtLineEnding { get; set; } private bool BreakIsDialog { get; set; } + private bool HasReset { get; set; } + private string ReplaceAllText { get; set; } public string SetTagsAndReturnTrimmed(string input, string sourceLanguage) { - if (string.IsNullOrEmpty(input)) + if (string.IsNullOrEmpty(HtmlUtil.RemoveHtmlTags(input, true))) { - return string.Empty; + ReplaceAllText = input; + return "..."; } var text = input.Trim(); @@ -43,6 +46,16 @@ namespace Nikse.SubtitleEdit.Core.Translate } } + // ASSA reset tag + if (text.Contains("\\r}", StringComparison.Ordinal) || + text.Contains("\\r\\", StringComparison.Ordinal)) + { + text = text.Replace("\\r}", "\\RESET}"); + text = text.Replace("\\r\\", "\\RESET\\"); + + HasReset = true; + } + // Italic tags if (text.StartsWith("", StringComparison.Ordinal) && text.EndsWith("", StringComparison.Ordinal) && text.Contains("" + Environment.NewLine + "") && Utilities.GetNumberOfLines(text) == 2 && Utilities.CountTagInText(text, "") == 2) { @@ -102,6 +115,11 @@ namespace Nikse.SubtitleEdit.Core.Translate { var text = input.Trim(); + if (ReplaceAllText != null) + { + return ReplaceAllText; + } + // Auto-break line if (AutoBreak) { @@ -139,6 +157,13 @@ namespace Nikse.SubtitleEdit.Core.Translate text = Font + text + ""; } + // ASSA reset tag + if (HasReset) + { + text = text.Replace("\\RESET}", "\\r}"); + text = text.Replace("\\RESET\\", "\\r\\"); + } + // SSA/ASS tags text = StartTags + text; diff --git a/src/libse/Translate/Processor/NextLineMergeTranslationProcessor.cs b/src/libse/Translate/Processor/NextLineMergeTranslationProcessor.cs index 641e407fa..232284fbf 100644 --- a/src/libse/Translate/Processor/NextLineMergeTranslationProcessor.cs +++ b/src/libse/Translate/Processor/NextLineMergeTranslationProcessor.cs @@ -58,7 +58,8 @@ namespace Nikse.SubtitleEdit.Core.Translate.Processor var baseUnitText = currentParagraphText; if (Configuration.Settings.Tools.TranslateAllowSplit && - !string.IsNullOrEmpty(nextParagraphText) && !string.IsNullOrEmpty(currentParagraphText) && + !string.IsNullOrEmpty(HtmlUtil.RemoveHtmlTags(nextParagraphText, true)) && + !string.IsNullOrEmpty(HtmlUtil.RemoveHtmlTags(currentParagraphText, true)) && (char.IsLetterOrDigit(currentParagraphText[currentParagraphText.Length - 1]) || currentParagraphText[currentParagraphText.Length - 1] == ',' || currentParagraphText[currentParagraphText.Length - 1] == '\u060C') && // \u060C = arabic comma char.IsLower(nextParagraphText[0]) && !currentParagraphText.Contains('-') && !nextParagraphText.Contains('-')) @@ -89,6 +90,11 @@ namespace Nikse.SubtitleEdit.Core.Translate.Processor var sourceTranslationUnit = sourceTranslationUnits[i]; var targetText = targetTexts[i].Trim(); + if (targetTexts.Count < sourceTranslationUnits.Count) + { + targetTexts.Add(string.Empty); + } + var currentText = targetText; string nextText = null; if (sourceTranslationUnit.SkipNext) diff --git a/src/libse/Translate/Service/GoogleTranslator1.cs b/src/libse/Translate/Service/GoogleTranslator1.cs index 40d3914b1..86872fcb4 100644 --- a/src/libse/Translate/Service/GoogleTranslator1.cs +++ b/src/libse/Translate/Service/GoogleTranslator1.cs @@ -53,7 +53,6 @@ namespace Nikse.SubtitleEdit.Core.Translate.Service var formatList = new List(); for (var index = 0; index < sourceParagraphs.Count; index++) { - var p = sourceParagraphs[index]; var f = new Formatting(); formatList.Add(f); @@ -182,6 +181,11 @@ namespace Nikse.SubtitleEdit.Core.Translate.Service { i++; } + else if (c == '\\' && result[i + 1] == '"') + { + c = '"'; + i++; + } else if (c == '"') { count++;