From bea492d248075f46d957e6eac3e8a4a335332f3d Mon Sep 17 00:00:00 2001 From: Ahmet Burukan Date: Thu, 30 Jul 2026 00:55:16 +0300 Subject: [PATCH] Save the day fix for Google Bad Request (400). This will pull text till a query limit (5k) and will require multiple presses to "Start + Apply" if some text to be translated is too long. In next revision may do Take(1) till max(10, payload limit) for enumerator and let it do its thing. However another bigger issue remains: a single source can be bigger than 5k limit and splitting it up may degrade the nmt translation context causing worse translation on Google's end. This needs some research on proper splitting. --- src/ResXManager.Translators/GoogleTranslator.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ResXManager.Translators/GoogleTranslator.cs b/src/ResXManager.Translators/GoogleTranslator.cs index 252e68f2..be6a627c 100644 --- a/src/ResXManager.Translators/GoogleTranslator.cs +++ b/src/ResXManager.Translators/GoogleTranslator.cs @@ -67,11 +67,19 @@ protected override async Task Translate(ITranslationSession translationSession) break; // Build out list of parameters + var payloadSoFar = 0; var parameters = new List(30); foreach (var item in sourceItems) { + var sourceText = RemoveKeyboardShortcutIndicators(item.Source); + + if (sourceText.Length + payloadSoFar > 4990) + continue; + + payloadSoFar += sourceText.Length; + // ReSharper disable once PossibleNullReferenceException - parameters.AddRange(new[] { "q", RemoveKeyboardShortcutIndicators(item.Source) }); + parameters.AddRange(new[] { "q", sourceText }); } parameters.AddRange(new[]