// // FreeTranslate_invoke // ------------------- // This is the function that we actually call to invoke the // online freetranslation translation // It should be called when the user selects from the context menu // static bool FreeTranslation_invoke(AV_View * /*v*/, EV_EditMethodCallData * /*d*/) { // Get the current view that the user is in. XAP_Frame * pFrame = XAP_App::getApp()->getLastFocussedFrame(); FV_View * pView = static_cast <FV_View *>(pFrame->getCurrentView()); std::string url("http://www.freetranslation.com"); if (!pView->isSelectionEmpty()) { std::string langCode; if (_getTranslationCode(pView, langCode)) { // Now we will figure out what words to translate // We need to get the Latin1 version of the current word. UT_UCS4Char *ucs4ST; pView->getSelectionText(*&ucs4ST); char * translate = _ucs4ToLatin1(ucs4ST); // URL encode the string (' ' -> %20, ...) // TODO this is not complete std::string srcText; for (char *p = translate; p && *p; ++p) { if (*p == ' ' || *p == '%' || *p == '&' || *p == '?' || (*p & 128)) // sometime char is signed. // do bitwise comparison for portability { char temp[4] = ""; sprintf(&temp[0], "%%%x", *p); srcText += temp; } else srcText += *p; } url = "http://ets.freetranslation.com/?Sequence=core"; url += "&Language="; url += langCode; url += "&SrcText="; url += srcText; DELETEPV(translate); FREEP(ucs4ST); XAP_App::getApp()->openURL(url.c_str()); } // else didn't get the translation code. don't show anything } else { XAP_App::getApp()->openURL(url.c_str()); } return true; }
// // BabelFish_invoke // ------------------- // This is the function that we actually call to invoke the // online babelfish translation // It should be called when the user selects from the context menu // static bool BabelFish_invoke(AV_View* /*v*/, EV_EditMethodCallData * /*d*/) { // Get the current view that the user is in. XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame(); FV_View* pView = static_cast<FV_View*>(pFrame->getCurrentView()); UT_String url ("http://babelfish.altavista.com"); if (!pView->isSelectionEmpty()) { // TODO: generate the correct language binding via the current // TODO: language and then the language dialog. Currently // TODO: english->german is hardcoded UT_String langCode; if ( _getTranslationCode ( pView, langCode ) ) { // Now we will figure out what words to translate url = "http://babelfish.altavista.com/tr?doit=done&tt=urltext"; url += "&lp="; url += langCode; url += "&urltext="; // We need to get the UTF-8 version of the current word. UT_String utf8; UT_UCS4Char *ucs4ST; pView->getSelectionText(*&ucs4ST); _ucsToUTF8( utf8, ucs4ST ); // URL encode the string (' ' -> %20, ...) // TODO this is not complete UT_String srcText; //for (char *p = utf8; p && *p; ++p) for (UT_uint32 i = 0; i < utf8.size(); ++i) { if (utf8[i] == ' ' || utf8[i] == '%' || utf8[i] == '&' || utf8[i] == '?' || (utf8[i] & 128)) { char temp[4] = ""; sprintf(&temp[0], "%%%x", utf8[i]); srcText += temp; } else srcText += utf8[i]; } url += srcText; FREEP(ucs4ST); XAP_App::getApp()->openURL( url.c_str() ); } // else didn't get the translation code. don't show anything } else { XAP_App::getApp()->openURL( url.c_str() ); } return true; }