Fix for recent translate commit

This commit is contained in:
niksedk 2023-01-27 23:10:36 +01:00
parent b42bf04b9e
commit a38e5fa408
3 changed files with 39 additions and 4 deletions

View File

@ -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("<i>", StringComparison.Ordinal) && text.EndsWith("</i>", StringComparison.Ordinal) && text.Contains("</i>" + Environment.NewLine + "<i>") && Utilities.GetNumberOfLines(text) == 2 && Utilities.CountTagInText(text, "<i>") == 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 + "</font>";
}
// ASSA reset tag
if (HasReset)
{
text = text.Replace("\\RESET}", "\\r}");
text = text.Replace("\\RESET\\", "\\r\\");
}
// SSA/ASS tags
text = StartTags + text;

View File

@ -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)

View File

@ -53,7 +53,6 @@ namespace Nikse.SubtitleEdit.Core.Translate.Service
var formatList = new List<Formatting>();
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++;