From e32227e90b8911200bfd103ff466ddb9231c6619 Mon Sep 17 00:00:00 2001
From: "Brad Payne (Vir Linden)" <vir@lindenlab.com>
Date: Fri, 21 Oct 2011 13:49:35 -0400
Subject: [PATCH] SH-2557 WIP - some cleanup, added error message to try to
 isolate causes of translation failure

---
 indra/newview/lltranslate.cpp     | 39 +++++++++++++++++++++++++++++++
 indra/newview/lltranslate.h       | 39 +++----------------------------
 indra/newview/llviewermessage.cpp |  2 +-
 3 files changed, 43 insertions(+), 37 deletions(-)
 mode change 100644 => 100755 indra/newview/lltranslate.cpp
 mode change 100644 => 100755 indra/newview/lltranslate.h
 mode change 100644 => 100755 indra/newview/llviewermessage.cpp

diff --git a/indra/newview/lltranslate.cpp b/indra/newview/lltranslate.cpp
old mode 100644
new mode 100755
index 2f60b6b90b4..3692f67a8dc
--- a/indra/newview/lltranslate.cpp
+++ b/indra/newview/lltranslate.cpp
@@ -53,6 +53,45 @@ const char* LLTranslate::m_GoogleData = "responseData";
 const char* LLTranslate::m_GoogleTranslation = "translatedText";
 const char* LLTranslate::m_GoogleLanguage = "detectedSourceLanguage";
 
+// virtual
+void LLTranslate::TranslationReceiver::completedRaw( U32 status,
+													 const std::string& reason,
+													 const LLChannelDescriptors& channels,
+													 const LLIOPipe::buffer_ptr_t& buffer)
+{
+	if (200 <= status && status < 300)
+	{
+		LLBufferStream istr(channels, buffer.get());
+		std::stringstream strstrm;
+		strstrm << istr.rdbuf();
+
+		const std::string result = strstrm.str();
+		std::string translation;
+		std::string detected_language;
+
+		if (!parseGoogleTranslate(result, translation, detected_language))
+		{
+			handleFailure();
+			return;
+		}
+				
+		// Fix up the response
+		LLStringUtil::replaceString(translation, "&lt;", "<");
+		LLStringUtil::replaceString(translation, "&gt;",">");
+		LLStringUtil::replaceString(translation, "&quot;","\"");
+		LLStringUtil::replaceString(translation, "&#39;","'");
+		LLStringUtil::replaceString(translation, "&amp;","&");
+		LLStringUtil::replaceString(translation, "&apos;","'");
+
+		handleResponse(translation, detected_language);
+	}
+	else
+	{
+		LL_WARNS("Translate") << "HTTP request for Google Translate failed with status " << status << ", reason: " << reason << LL_ENDL;
+		handleFailure();
+	}
+}
+
 //static
 void LLTranslate::translateMessage(LLHTTPClient::ResponderPtr &result, const std::string &from_lang, const std::string &to_lang, const std::string &mesg)
 {
diff --git a/indra/newview/lltranslate.h b/indra/newview/lltranslate.h
old mode 100644
new mode 100755
index e85a42e878d..c7d6eac33f1
--- a/indra/newview/lltranslate.h
+++ b/indra/newview/lltranslate.h
@@ -43,8 +43,8 @@ public :
 		{
 		}
 
-		virtual void handleResponse(const std::string &translation, const std::string &recognized_lang) {};
-		virtual void handleFailure() {};
+		virtual void handleResponse(const std::string &translation, const std::string &recognized_lang) = 0;
+		virtual void handleFailure() = 0;
 
 	public:
 		~TranslationReceiver()
@@ -54,40 +54,7 @@ public :
 		virtual void completedRaw(	U32 status,
 									const std::string& reason,
 									const LLChannelDescriptors& channels,
-									const LLIOPipe::buffer_ptr_t& buffer)
-		{
-			if (200 <= status && status < 300)
-			{
-				LLBufferStream istr(channels, buffer.get());
-				std::stringstream strstrm;
-				strstrm << istr.rdbuf();
-
-				const std::string result = strstrm.str();
-				std::string translation;
-				std::string detected_language;
-
-				if (!parseGoogleTranslate(result, translation, detected_language))
-				{
-					handleFailure();
-					return;
-				}
-				
-				// Fix up the response
-				LLStringUtil::replaceString(translation, "&lt;", "<");
-				LLStringUtil::replaceString(translation, "&gt;",">");
-				LLStringUtil::replaceString(translation, "&quot;","\"");
-				LLStringUtil::replaceString(translation, "&#39;","'");
-				LLStringUtil::replaceString(translation, "&amp;","&");
-				LLStringUtil::replaceString(translation, "&apos;","'");
-
-				handleResponse(translation, detected_language);
-			}
-			else
-			{
-				LL_WARNS("Translate") << "HTTP request for Google Translate failed with status " << status << ", reason: " << reason << LL_ENDL;
-				handleFailure();
-			}
-		}
+									const LLIOPipe::buffer_ptr_t& buffer);
 
 	protected:
 		const std::string m_toLang;
diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp
old mode 100644
new mode 100755
index 369d2d757dd..04b901ed0e3
--- a/indra/newview/llviewermessage.cpp
+++ b/indra/newview/llviewermessage.cpp
@@ -3129,7 +3129,7 @@ public :
 
 	void handleFailure()
 	{
-		LLTranslate::TranslationReceiver::handleFailure();
+		llwarns << "translation failed for mesg " << m_origMesg << llendl;
 		m_chat.mText += " (?)";
 
 		LLNotificationsUI::LLNotificationManager::instance().onChat(m_chat, m_toastArgs);
-- 
GitLab