diff --git a/extensions/bingtranslate.cpp b/extensions/bingtranslate.cpp index 86fabe3..321bbac 100644 --- a/extensions/bingtranslate.cpp +++ b/extensions/bingtranslate.cpp @@ -58,18 +58,14 @@ QStringList languages std::pair Translate(const std::wstring& text) { - std::wstring translateFrom; - if (HttpRequest httpRequest{ L"Mozilla/5.0 Textractor", L"www.bing.com", L"POST", FormatString(L"/tdetect?text=%s", Escape(text)).c_str() }) translateFrom = httpRequest.response; - else return { false, FormatString(L"%s (code=%u)", TRANSLATION_ERROR, httpRequest.errorCode) }; - if (HttpRequest httpRequest{ L"Mozilla/5.0 Textractor", L"www.bing.com", L"POST", - FormatString(L"/ttranslate?from=%s&to=%s&text=%s", translateFrom, translateTo->c_str(), Escape(text)).c_str() + FormatString(L"/ttranslatev3?fromLang=auto-detect&to=%s&text=%s", translateTo->c_str(), Escape(text)).c_str() }) - // Response formatted as JSON: translation starts with :" and ends with "} - if (std::wsmatch results; std::regex_search(httpRequest.response, results, std::wregex(L":\"(.+)\"\\}"))) return { true, results[1] }; + // Response formatted as JSON: translation starts with text":" and ends with "," + if (std::wsmatch results; std::regex_search(httpRequest.response, results, std::wregex(L"text\":\"(.+)\"\\,"))) return { true, results[1] }; else return { false, TRANSLATION_ERROR }; else return { false, FormatString(L"%s (code=%u)", TRANSLATION_ERROR, httpRequest.errorCode) }; } diff --git a/extensions/googletranslate.cpp b/extensions/googletranslate.cpp index 125a1a3..125ac0a 100644 --- a/extensions/googletranslate.cpp +++ b/extensions/googletranslate.cpp @@ -95,7 +95,7 @@ std::wstring GetTranslationUri(const std::wstring& text, unsigned TKK) a %= 1000000; b ^= a; - 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); + return FormatString(L"/translate_a/single?client=webapp&dt=ld&dt=rm&dt=t&sl=auto&tl=%s&tk=%u.%u&q=%s", translateTo->c_str(), a, b, escapedText); } bool IsHash(const std::wstring& result)