Skip to content

Commit

Permalink
Merge pull request #630 from tkefauver/googlelite-clients5-subdomain
Browse files Browse the repository at this point in the history
Changed GoogleLite subdomain to clients5
  • Loading branch information
tom-englert authored Feb 19, 2024
2 parents 5116a5b + 1e56fd2 commit 44ec922
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/ResXManager.Translators/GoogleTranslatorLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class GoogleTranslatorLite : TranslatorBase
{
private static readonly Uri _uri = new("https://translate.google.com/");

public GoogleTranslatorLite( )
public GoogleTranslatorLite()
: base("GoogleLite", "Google Lite", _uri, null)
{
}
Expand All @@ -54,16 +54,15 @@ protected override async Task Translate(ITranslationSession translationSession)
// ReSharper disable once PossibleNullReferenceException
parameters.AddRange(new[]
{
"client", "gtx",
"client", "dict-chrome-ex",
"sl", GoogleLangCode(translationSession.SourceLanguage),
"tl", GoogleLangCode(targetCulture),
"dt", "t",
"q", RemoveKeyboardShortcutIndicators(sourceItems[0].Source)
});

// ReSharper disable once AssignNullToNotNullAttribute
var response = await GetHttpResponse(
"https://translate.googleapis.com/translate_a/single",
"https://clients5.google.com/translate_a/t",
parameters,
translationSession.CancellationToken).ConfigureAwait(false);

Expand Down Expand Up @@ -102,8 +101,7 @@ private static async Task<string> GetHttpResponse(string baseUrl, ICollection<st

#pragma warning disable CA2016 // Forward the 'CancellationToken' parameter to methods => not available in .NET Framework
var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
// Using string.Substring => System.Index or System.Range not available in .NET Framework
result = result.Substring(4, result.IndexOf("\",\"", 4, StringComparison.Ordinal) - 4);
result = result.Substring(2, result.Length - 4);
return Regex.Unescape(result);
}

Expand Down

0 comments on commit 44ec922

Please sign in to comment.