Skip to content
Snippets Groups Projects
Commit c3a2781c authored by Alexander Gavriliuk's avatar Alexander Gavriliuk Committed by Guru
Browse files

SL-20078 Remove Google Translation UI (just fix error processing)

parent 4bef4f94
No related branches found
No related tags found
No related merge requests found
...@@ -253,7 +253,7 @@ void LLTranslationAPIHandler::translateMessageCoro(LanguagePair_t fromTo, std::s ...@@ -253,7 +253,7 @@ void LLTranslationAPIHandler::translateMessageCoro(LanguagePair_t fromTo, std::s
try try
{ {
res = this->parseResponse(httpResults, parseResult, body, translation, detected_lang, err_msg); res = parseResponse(httpResults, parseResult, body, translation, detected_lang, err_msg);
} }
catch (std::out_of_range&) catch (std::out_of_range&)
{ {
...@@ -293,8 +293,6 @@ void LLTranslationAPIHandler::translateMessageCoro(LanguagePair_t fromTo, std::s ...@@ -293,8 +293,6 @@ void LLTranslationAPIHandler::translateMessageCoro(LanguagePair_t fromTo, std::s
if (!failure.empty()) if (!failure.empty())
failure(status, err_msg); failure(status, err_msg);
} }
} }
//========================================================================= //=========================================================================
...@@ -353,7 +351,6 @@ class LLGoogleTranslationHandler : public LLTranslationAPIHandler ...@@ -353,7 +351,6 @@ class LLGoogleTranslationHandler : public LLTranslationAPIHandler
std::string& translation, std::string& translation,
std::string& detected_lang); std::string& detected_lang);
static std::string getAPIKey(); static std::string getAPIKey();
}; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
...@@ -391,36 +388,37 @@ bool LLGoogleTranslationHandler::checkVerificationResponse( ...@@ -391,36 +388,37 @@ bool LLGoogleTranslationHandler::checkVerificationResponse(
// virtual // virtual
bool LLGoogleTranslationHandler::parseResponse( bool LLGoogleTranslationHandler::parseResponse(
const LLSD& http_response, const LLSD& http_response,
int& status, int& status,
const std::string& body, const std::string& body,
std::string& translation, std::string& translation,
std::string& detected_lang, std::string& detected_lang,
std::string& err_msg) const std::string& err_msg) const
{ {
const std::string& text = !body.empty() ? body : http_response["error_body"].asStringRef();
Json::Value root; Json::Value root;
Json::Reader reader; Json::Reader reader;
if (!reader.parse(body, root)) if (reader.parse(text, root))
{ {
err_msg = reader.getFormatedErrorMessages(); if (root.isObject())
return false; {
// Request succeeded, extract translation from the XML body.
if (parseTranslation(root, translation, detected_lang))
return true;
// Request failed. Extract error message from the XML body.
parseErrorResponse(root, status, err_msg);
}
} }
else
if (!root.isObject()) // empty response? should not happen
{ {
return false; // XML parsing failed. Extract error message from the XML parser.
} err_msg = reader.getFormatedErrorMessages();
if (status != HTTP_OK)
{
// Request failed. Extract error message from the response.
parseErrorResponse(root, status, err_msg);
return false;
} }
// Request succeeded, extract translation from the response. return false;
return parseTranslation(root, translation, detected_lang);
} }
// virtual // virtual
...@@ -493,7 +491,7 @@ void LLGoogleTranslationHandler::verifyKey(const LLSD &key, LLTranslate::KeyVeri ...@@ -493,7 +491,7 @@ void LLGoogleTranslationHandler::verifyKey(const LLSD &key, LLTranslate::KeyVeri
/*virtual*/ /*virtual*/
void LLGoogleTranslationHandler::initHttpHeader(LLCore::HttpHeaders::ptr_t headers, const std::string& user_agent) const void LLGoogleTranslationHandler::initHttpHeader(LLCore::HttpHeaders::ptr_t headers, const std::string& user_agent) const
{ {
headers->append(HTTP_OUT_HEADER_ACCEPT, HTTP_CONTENT_TEXT_PLAIN); headers->append(HTTP_OUT_HEADER_ACCEPT, HTTP_CONTENT_JSON);
headers->append(HTTP_OUT_HEADER_USER_AGENT, user_agent); headers->append(HTTP_OUT_HEADER_USER_AGENT, user_agent);
} }
...@@ -503,8 +501,7 @@ void LLGoogleTranslationHandler::initHttpHeader( ...@@ -503,8 +501,7 @@ void LLGoogleTranslationHandler::initHttpHeader(
const std::string& user_agent, const std::string& user_agent,
const LLSD &key) const const LLSD &key) const
{ {
headers->append(HTTP_OUT_HEADER_ACCEPT, HTTP_CONTENT_TEXT_PLAIN); initHttpHeader(headers, user_agent);
headers->append(HTTP_OUT_HEADER_USER_AGENT, user_agent);
} }
LLSD LLGoogleTranslationHandler::sendMessageAndSuspend(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t adapter, LLSD LLGoogleTranslationHandler::sendMessageAndSuspend(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t adapter,
...@@ -1314,5 +1311,4 @@ LLTranslationAPIHandler& LLTranslate::getHandler(EService service) ...@@ -1314,5 +1311,4 @@ LLTranslationAPIHandler& LLTranslate::getHandler(EService service)
} }
return azure; return azure;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment