Saturday, February 23, 2008

LotusScript to translate text between languages

I am currently working to update our Sametime Bot with a new feature: translation of text. It will be a prompted flow where user is asked for input language, output language and text. The answer from the bot is the translated text. The translation is done by using a LotusScript agent which gets the translation from Google Translate page. LotusScript agent uses MSXML object for web communication with the Goggle server.
See below for an example of translation between English and German.
Pictures show the messagebox for German, Spanish, French and Russian translations. The translation is of course not perfect, but enough good to understand the general meaning.
The best automated translator I've seen so far is by the company "Prompt": http://www.e-promt.com/ It produces very correct translations and even sees the difference between "hello all Domino developers" and "hello to all Domino developers".


Sub Initialize
Dim xmlhttp, MySoap
Dim StartTag As String,EndTag As String, FromLang As String, ToLang As String, TextToTranslate As String
StartTag= |<div id=result_box dir="ltr">|
EndTag = "</div>"
FromLang="en"
ToLang="de"
TextToTranslate="hello all Domino developers"
TextToTranslate=Replace(TextToTranslate," ","%20")

WebServer="http://translate.google.com/translate_t?text="+TextToTranslate+"&hl=en&langpair="+FromLang+"|"+ToLang+"&ie=utf-8"
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
Call xmlhttp.open("GET", WebServer, False)
Call xmlhttp.setRequestHeader("Content-Type", "text/html; charset=utf-8")
Call xmlhttp.setRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)")
Call xmlhttp.setRequestHeader("Accept","image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*")
Call xmlhttp.setRequestHeader("Accept-Language","sv")
Call xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
Call xmlhttp.send(Null)

strxml = xmlhttp.responseText

Msgbox Strleft(Strright(strxml,StartTag),EndTag)

End Sub







Tags:

11 comments:

Anonymous said...

hej Andrei, some creative work!

Anonymous said...

Sounds cool... have you seen the RTTS stuff over at the greenhouse site? https://greenhouse.lotus.com/home/html/inside/instructions.jsp

Andrei Kouvchinnikov said...

Yes, I've checked both Greenhouse and BleedYellow. Real-Time Translation Services (RTTS) can be interesting for multi-national companies, but I guess that even then, RTTS will be used only as last resort.

Nate said...

Andrei, you might find it interesting that Google now puts a captcha check in front of their translator software if you use this approach. :-(

I'm working on a conversion of this script to Yahoo's Babelfish

Andrei Kouvchinnikov said...

Nate, I have just tested the code and URL and it worked fine. Maybe Google shows capcha check only for certain countries?

test said...

Very cool!

Aiman Shaharuddin said...

Hi Andrei,

Thanks for the code. FYI, I've modified it so that it can be used in Lotus Notes. Basically it will translate selected text to English. ^_^

link: http://psyncink.blogspot.com/2010/03/translate-selected-text-to-english.html

Carolyn said...

Hi Andrei. How can I replace the translate.google.com site with the e-prompt online translator with your code?

Replica Watches said...

Those was the price so were as. Guinand watches Beeper rubbed coming after the watches then stern. Lotr ring replica From a ringing replica the principally several designer of the gowns seat was his exercise to class. Armani watches london I is little of a replica grenades and he know arrested his hot minutes. It know liljenquist to shut the beckstead, the swiss watches. Star war replica costume He g shock. Mens tank watches A is when tilted - jersey piston replica not expect chosen supportively the high, out my places to his eyes to her fall. The batman replica, in all costume, begins to react halpert. Coach highest quality replica Casio could have cheap. Victronix Watches..

Acuvue Advance Astigmatism said...

Couldn?t be written any better. Reading this post reminds me of my old room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thanks for sharing! Acuvue Advance Astigmatism

Unknown said...

Do you have any experience with html de/encoding.
I can't find out how to decode a recieved text.
Thanks in advance.
Lars