diff options
author | Patrick Sapinski | 2010-08-24 03:04:20 -0400 |
---|---|---|
committer | McCabe Maxsted | 2010-08-30 17:04:59 -0700 |
commit | ded1245db74ae4c97d174c5779f8572ee2f032fa (patch) | |
tree | f42c33f233ed68e715a0ac4c74ddc043f43a68da /linden/indra/newview/lltranslate.h | |
parent | Added debug setting UseLegacyChatLogsFolder for saving chat.txt and IM logs i... (diff) | |
download | meta-impy-ded1245db74ae4c97d174c5779f8572ee2f032fa.zip meta-impy-ded1245db74ae4c97d174c5779f8572ee2f032fa.tar.gz meta-impy-ded1245db74ae4c97d174c5779f8572ee2f032fa.tar.bz2 meta-impy-ded1245db74ae4c97d174c5779f8572ee2f032fa.tar.xz |
added spellcheck + translation from Emerald Viewer. references to modularsystems.sl should be changed!
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/lltranslate.h | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/linden/indra/newview/lltranslate.h b/linden/indra/newview/lltranslate.h new file mode 100644 index 0000000..2723c43 --- /dev/null +++ b/linden/indra/newview/lltranslate.h | |||
@@ -0,0 +1,125 @@ | |||
1 | /** | ||
2 | * @file lltranslate.h | ||
3 | * @brief Human language translation class and JSON response receiver. | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2009&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2009, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at | ||
21 | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
22 | * | ||
23 | * By copying, modifying or distributing this software, you acknowledge | ||
24 | * that you have read and understood your obligations described above, | ||
25 | * and agree to abide by those obligations. | ||
26 | * | ||
27 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
28 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
29 | * COMPLETENESS OR PERFORMANCE. | ||
30 | * $/LicenseInfo$ | ||
31 | */ | ||
32 | |||
33 | #ifndef LL_LLTRANSLATE_H | ||
34 | #define LL_LLTRANSLATE_H | ||
35 | |||
36 | #include "llhttpclient.h" | ||
37 | #include "llbufferstream.h" | ||
38 | #include "jsoncpp/reader.h" | ||
39 | |||
40 | class LLTranslate | ||
41 | { | ||
42 | public : | ||
43 | class TranslationReceiver: public LLHTTPClient::Responder | ||
44 | { | ||
45 | protected: | ||
46 | TranslationReceiver(const std::string &fromLang, const std::string &toLang) | ||
47 | : m_fromLang(fromLang), | ||
48 | m_toLang(toLang) | ||
49 | { | ||
50 | } | ||
51 | |||
52 | virtual void handleResponse(const std::string &translation, const std::string &recognizedLang) {} | ||
53 | virtual void handleFailure() {}; | ||
54 | |||
55 | public: | ||
56 | ~TranslationReceiver() | ||
57 | { | ||
58 | } | ||
59 | |||
60 | virtual void error(U32 status, const std::string& reason) | ||
61 | { | ||
62 | LL_WARNS("Translate") << "URL Request error: " << reason << LL_ENDL; | ||
63 | handleFailure(); | ||
64 | } | ||
65 | |||
66 | virtual void completedRaw( | ||
67 | U32 status, | ||
68 | const std::string& reason, | ||
69 | const LLChannelDescriptors& channels, | ||
70 | const LLIOPipe::buffer_ptr_t& buffer) | ||
71 | { | ||
72 | LLBufferStream istr(channels, buffer.get()); | ||
73 | |||
74 | std::stringstream strstrm; | ||
75 | strstrm << istr.rdbuf(); | ||
76 | const std::string result = strstrm.str(); | ||
77 | |||
78 | std::string translation; | ||
79 | std::string detectedLanguage; | ||
80 | |||
81 | if (!parseGoogleTranslate(result, translation, detectedLanguage)) | ||
82 | { | ||
83 | handleFailure(); | ||
84 | return; | ||
85 | } | ||
86 | |||
87 | // Fix up the response | ||
88 | stringReplaceAll( translation, "<","<"); | ||
89 | stringReplaceAll( translation, ">",">"); | ||
90 | stringReplaceAll( translation, ""","\""); | ||
91 | stringReplaceAll( translation, "'","'"); | ||
92 | stringReplaceAll( translation, "&","&"); | ||
93 | stringReplaceAll( translation, "'","'"); | ||
94 | |||
95 | handleResponse(translation, detectedLanguage); | ||
96 | } | ||
97 | |||
98 | protected: | ||
99 | const std::string m_toLang; | ||
100 | const std::string m_fromLang; | ||
101 | }; | ||
102 | |||
103 | static void translateMessage(LLHTTPClient::ResponderPtr &result, const std::string &fromLang, const std::string &toLang, const std::string &mesg); | ||
104 | static float m_GoogleTimeout; | ||
105 | static std::string getTranslateLanguage(); | ||
106 | |||
107 | private: | ||
108 | static void getTranslateUrl(std::string &translateUrl, const std::string &fromLang, const std::string &toLang, const std::string &text); | ||
109 | static void stringReplaceAll(std::string& context, const std::string& from, const std::string& to); | ||
110 | static BOOL parseGoogleTranslate(const std::string result, std::string &translation, std::string &detectedLanguage); | ||
111 | |||
112 | static LLSD m_Header; | ||
113 | static const char* m_GoogleURL; | ||
114 | static const char* m_GoogleLangSpec; | ||
115 | static const char* m_AcceptHeader; | ||
116 | static const char* m_AcceptType; | ||
117 | static const char* m_AgentHeader; | ||
118 | static const char* m_UserAgent; | ||
119 | |||
120 | static const char* m_GoogleData; | ||
121 | static const char* m_GoogleTranslation; | ||
122 | static const char* m_GoogleLanguage; | ||
123 | }; | ||
124 | |||
125 | #endif | ||