From 5f5c5d5a1a144abcc74ef55d534ac62ed3116d66 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Fri, 21 Jun 2019 23:16:23 -0400 Subject: [PATCH] update translation api --- extensions/googletranslate.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extensions/googletranslate.cpp b/extensions/googletranslate.cpp index ef2a263..b9c9a22 100644 --- a/extensions/googletranslate.cpp +++ b/extensions/googletranslate.cpp @@ -97,6 +97,11 @@ std::wstring GetTranslationUri(const std::wstring& text, unsigned TKK) return FormatString(L"/translate_a/single?client=t&dt=ld&dt=rm&dt=t&tl=%s&tk=%u.%u&q=%s", translateTo->c_str(), a, b, escapedText); } +bool IsHash(const std::wstring& result) +{ + return std::all_of(result.begin(), result.end(), [](auto ch) { return (ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'z'); }); +} + std::pair Translate(const std::wstring& text) { static unsigned TKK = 0; @@ -112,7 +117,7 @@ std::pair Translate(const std::wstring& text) { std::wstring translation; for (std::wsmatch results; std::regex_search(httpRequest.response, results, std::wregex(L"\\[\"(.*?)\",[n\"]")); httpRequest.response = results.suffix()) - translation += std::wstring(results[1]) + L" "; + if (!IsHash(results[1])) translation += std::wstring(results[1]) + L" "; if (!translation.empty()) return { true, translation }; } return { false, FormatString(L"%s (TKK=%u)", TRANSLATION_ERROR, _InterlockedExchange(&TKK, 0)) };