From c7b5dd1f0a74bae669e9806a5d5a4247089d4e38 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sat, 20 Apr 2024 12:14:43 +0200 Subject: [PATCH] Try to workaround LibreTranslate issue - thx GOvEy1nw :) Fix #8223 --- src/libse/AutoTranslate/LibreTranslate.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libse/AutoTranslate/LibreTranslate.cs b/src/libse/AutoTranslate/LibreTranslate.cs index faea6395f..891e0f039 100644 --- a/src/libse/AutoTranslate/LibreTranslate.cs +++ b/src/libse/AutoTranslate/LibreTranslate.cs @@ -58,7 +58,7 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate var input = "{\"q\": \"" + Json.EncodeJsonText(text.Trim()) + "\", \"source\": \"" + sourceLanguageCode + "\", \"target\": \"" + targetLanguageCode + "\"" + apiKey + "}"; var content = new StringContent(input, Encoding.UTF8); content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); - var result = _httpClient.PostAsync("translate", content).Result; + var result = _httpClient.PostAsync("translate", content, cancellationToken).Result; var bytes = await result.Content.ReadAsByteArrayAsync(); var json = Encoding.UTF8.GetString(bytes).Trim(); if (!result.IsSuccessStatusCode) @@ -74,6 +74,9 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate return string.Empty; } + resultText = resultText.Replace("
", Environment.NewLine); + resultText = resultText.Replace(" /> ", " "); // https://github.com/SubtitleEdit/subtitleedit/issues/8223 + return Json.DecodeJsonText(resultText).Trim(); }