Try to workaround LibreTranslate issue - thx GOvEy1nw :)

Fix #8223
This commit is contained in:
Nikolaj Olsson 2024-04-20 12:14:43 +02:00
parent 903b2c2a73
commit c7b5dd1f0a

View File

@ -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("<br />", Environment.NewLine);
resultText = resultText.Replace(" /> ", " "); // https://github.com/SubtitleEdit/subtitleedit/issues/8223
return Json.DecodeJsonText(resultText).Trim();
}