mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
Merge branch 'main' of https://github.com/SubtitleEdit/subtitleedit
This commit is contained in:
commit
4603e550b0
@ -17,8 +17,14 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
|
||||
/// </summary>
|
||||
string Url { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Represents an error message or description.
|
||||
/// </summary>
|
||||
string Error { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum number of characters that can be translated at once.
|
||||
/// </summary>
|
||||
int MaxCharacters { get; }
|
||||
|
||||
/// <summary>
|
||||
@ -37,8 +43,14 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
|
||||
List<TranslationPair> GetSupportedTargetLanguages();
|
||||
|
||||
/// <summary>
|
||||
/// Do translation.
|
||||
/// Translates the given text from the source language to the target language.
|
||||
/// </summary>
|
||||
/// <param name="text">The text to be translated.</param>
|
||||
/// <param name="sourceLanguageCode">The language code of the source language.</param>
|
||||
/// <param name="targetLanguageCode">The language code of the target language.</param>
|
||||
/// <param name="cancellationToken">The cancellation token to cancel the translation process.</param>
|
||||
/// <returns>A task that represents the asynchronous translation operation.
|
||||
/// The task result contains the translated text.</returns>
|
||||
Task<string> Translate(string text, string sourceLanguageCode, string targetLanguageCode, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
|
||||
public class MyMemoryApi : IAutoTranslator
|
||||
{
|
||||
private IDownloader _httpClient;
|
||||
private readonly SeJsonParser _jsonParser = new SeJsonParser();
|
||||
|
||||
public static string StaticName { get; set; } = "MyMemory Translate";
|
||||
public string Name => StaticName;
|
||||
@ -212,8 +213,7 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
|
||||
|
||||
var url = $"?langpair={sourceLanguageCode}|{targetLanguageCode}{apiKey}&q={Utilities.UrlEncode(text)}";
|
||||
var jsonResultString = _httpClient.GetStringAsync(url).Result;
|
||||
var parser = new SeJsonParser();
|
||||
var textResult = parser.GetFirstObject(jsonResultString, "translatedText");
|
||||
var textResult = _jsonParser.GetFirstObject(jsonResultString, "translatedText");
|
||||
var result = Json.DecodeJsonText(textResult);
|
||||
|
||||
try
|
||||
|
Loading…
Reference in New Issue
Block a user