mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-25 04:33:04 +01:00
Integrate SeJsonParser as class field in MyMemoryApi
In the MyMemoryApi class, SeJsonParser is now instantiated as a class field instead of a local variable in the GetTranslatedTextAsync method. This change was implemented to simplify the retrieval of translated text from JSON results.
This commit is contained in:
parent
8ecdad90ad
commit
c2a9faed0a
@ -13,6 +13,7 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
|
|||||||
public class MyMemoryApi : IAutoTranslator
|
public class MyMemoryApi : IAutoTranslator
|
||||||
{
|
{
|
||||||
private IDownloader _httpClient;
|
private IDownloader _httpClient;
|
||||||
|
private readonly SeJsonParser _jsonParser = new SeJsonParser();
|
||||||
|
|
||||||
public static string StaticName { get; set; } = "MyMemory Translate";
|
public static string StaticName { get; set; } = "MyMemory Translate";
|
||||||
public string Name => StaticName;
|
public string Name => StaticName;
|
||||||
@ -212,8 +213,7 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
|
|||||||
|
|
||||||
var url = $"?langpair={sourceLanguageCode}|{targetLanguageCode}{apiKey}&q={Utilities.UrlEncode(text)}";
|
var url = $"?langpair={sourceLanguageCode}|{targetLanguageCode}{apiKey}&q={Utilities.UrlEncode(text)}";
|
||||||
var jsonResultString = _httpClient.GetStringAsync(url).Result;
|
var jsonResultString = _httpClient.GetStringAsync(url).Result;
|
||||||
var parser = new SeJsonParser();
|
var textResult = _jsonParser.GetFirstObject(jsonResultString, "translatedText");
|
||||||
var textResult = parser.GetFirstObject(jsonResultString, "translatedText");
|
|
||||||
var result = Json.DecodeJsonText(textResult);
|
var result = Json.DecodeJsonText(textResult);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
Loading…
Reference in New Issue
Block a user