From be185233d1512f14d55907361df2f516cb976b3d Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 6 Dec 2018 03:56:49 -0500 Subject: [PATCH] fix google translate (new api) --- extensions/googletranslate/googletranslate.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/extensions/googletranslate/googletranslate.cpp b/extensions/googletranslate/googletranslate.cpp index a424b6f..e7732c3 100644 --- a/extensions/googletranslate/googletranslate.cpp +++ b/extensions/googletranslate/googletranslate.cpp @@ -162,11 +162,10 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) if (WinHttpSendRequest(request, NULL, 0, NULL, 0, 0, NULL)) { DWORD bytesRead; - char buffer[100000] = {}; // Google Translate page is ~64kb + char buffer[200000] = {}; // Google Translate page is ~180kb (good god the bloat >_>) WinHttpReceiveResponse(request, NULL); - WinHttpReadData(request, buffer, 100000, &bytesRead); - if (strstr(buffer, "a\\x3d")) TKK = strtoll(strstr(buffer, "a\\x3d") + 5, nullptr, 10) + strtoll(strstr(buffer, "b\\x3d") + 5, nullptr, 10); - else TKK = strtoll(strstr(buffer, "TKK") + 12, nullptr, 10); + WinHttpReadData(request, buffer, 200000, &bytesRead); + if (std::cmatch results; std::regex_search(buffer, results, std::regex("(\\d{7,})'"))) TKK = stoll(results[1]); } WinHttpCloseHandle(request); } @@ -200,7 +199,7 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) } } - if (translation == L"") translation = L"Error while translating."; + if (translation.empty()) translation = L"Error while translating (TKK=" + std::to_wstring(TKK) + L")"; sentence += L"\r\n" + translation; return true; } \ No newline at end of file