diff --git a/wordref/src/WordReference.cpp b/wordref/src/WordReference.cpp
index c31bfaa..9131cd9 100644
--- a/wordref/src/WordReference.cpp
+++ b/wordref/src/WordReference.cpp
@@ -65,6 +65,22 @@ namespace {
std::string jsonResponse(http.GetPage(oss.str()));
return libjson::parse(libjson::to_json_string(jsonResponse));
}
+
+ ///-------------------------------------------------------------------------
+ ///-------------------------------------------------------------------------
+ void PrintTranslation (std::wostream& parStream, const JSONNode& parNode) {
+ for (JSONNode::const_iterator itTr = parNode.begin(), itTrEND = parNode.end(); itTr != itTrEND; ++itTr) {
+ JSONNode::const_iterator originalTerm = itTr->find(json_string(L"OriginalTerm"));
+ if (originalTerm != itTr->end()) {
+ JSONNode::const_iterator term(originalTerm->find(L"term")),
+ sense(originalTerm->find(L"sense"));
+ if (term != originalTerm->end() and sense != originalTerm->end()) {
+ parStream << originalTerm->find(L"term")->as_string();
+ parStream << L": (" << originalTerm->find(L"sense")->as_string() << L")\n";
+ }
+ }
+ }
+ }
} //unnamed namespace
///-----------------------------------------------------------------------------
@@ -153,6 +169,15 @@ std::string WordReference::GetApiVersion() {
///-----------------------------------------------------------------------------
///-----------------------------------------------------------------------------
-void WordReference::Translate (const std::string& parWord) {
+void WordReference::Translate (const std::string& parWord, std::wostream& parStream) {
JSONNode root = QueryJSon(m_langFrom, m_langTo, m_apiKey, parWord);
+ for (JSONNode::const_iterator itCur = root.begin(), itCurEND = root.end(); itCur != itCurEND; ++itCur) {
+ const std::wstring nodeName(libjson::to_std_wstring(itCur->name()));
+ if (itCur->type() == JSON_NODE and nodeName.compare(0, 4, L"term") == 0) {
+ JSONNode::const_iterator principTranslations(itCur->find(L"PrincipalTranslations"));
+ if (principTranslations != itCur->end()) {
+ PrintTranslation(parStream, *principTranslations);
+ }
+ }
+ }
}
diff --git a/wordref/src/WordReference.hpp b/wordref/src/WordReference.hpp
index 1eafaf2..71c131a 100644
--- a/wordref/src/WordReference.hpp
+++ b/wordref/src/WordReference.hpp
@@ -42,7 +42,7 @@ public:
std::string GetHttpLink ( const char* parWord );
std::string GetHttpLink ( const std::string& parWord );
static std::string GetApiVersion ( void );
- void Translate ( const std::string& parWord );
+ void Translate ( const std::string& parWord, std::wostream& parStream );
private:
std::string m_langFrom;
diff --git a/wordref/src/main.cpp b/wordref/src/main.cpp
index 6c7ece3..8b0408b 100644
--- a/wordref/src/main.cpp
+++ b/wordref/src/main.cpp
@@ -102,8 +102,8 @@ int main (int parArgc, const char* const parArgv[]) {
}
WordReference wref("en", "it", DefApiKey);
- wref.Translate("house");
+ wref.Translate("house", std::wcout);
- std::cout << wref.GetHttpLink("north face") << "\nWritten by King_DuckZ; © WordReference.com" << std::endl;
+ std::wcout << wref.GetHttpLink("north face") << L"\nWritten by King_DuckZ; © WordReference.com" << std::endl;
return 0;
}
diff --git a/wordref/src/main.hpp b/wordref/src/main.hpp
index 48a8002..d300a2d 100644
--- a/wordref/src/main.hpp
+++ b/wordref/src/main.hpp
@@ -24,5 +24,6 @@ along with this program. If not, see .
#include
#include
#include
+#include
#endif