While waiting for Lost to start, I was catching up on some RSS feeds. I just dropped TechCrunch & anything mentioning Scoble in my recent news feed pruning which has decreased my news volume nicely. One noteworthy item today was the launch of Google's AJAX Language API. I think it's the only translation web service out there. One downside is that it's JavaScript only. It would be nicer if there was a REST web service to call to make it easier to integrate into desktop apps or to bulk convert text in a service.
A cool use of it I think would be to integrate into existing IM clients. I have a few French & Spanish speaking friends so it would be helpful if my IM client could auto-translate since my foreign language skills are at a kindergarten level.
Lately I've been using Office Communicator since we have a new kick a$$ VOIP setup..(so nice to be able to transfer an IM conversation to a phone call and chat via my USB speaker phone.) Anyway, I was looking for something to try out the Google translation API and I started looking at the communicator API. I didn't realize you could just add a new tab of HTML via a quick registry setting. In about 15 minutes I was able to create this:
It's probably not super useful, but it's always fun to try out new stuff.
Adding a New Tab to Communicator
This TechNet article explains how to add a new tab in communicator. Basically you just need to create a new registry string value under HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Communicator.
I set the value to "file:///C:/communicatorTab.xml"
In the XML file I put:
<?xml version="1.0" ?>
<tabdata>
<tab>
<image>file:///c:/communicatorTab.png</image>
<accessibility>both</accessibility>
<userid>false</userid>
<name>the name to display on the tab</name>
<tooltip>the tooltip to show</tooltip>
<contenturl>http://localhost/communicatorTab.htm</contenturl>
<contactid>false</contactid>
<method>get</method>
<tabid>1</tabid>
</tab>
</tabdata>
For the contentUrl, you need to point to an HTML file which will be displayed in the tab. I wasn't able to get it working via "file:///c:/communicatorTab.htm", but according to the docs that should work. I'm running IIS so I just put it on my web server. If you are sharing this, you'd probably want to put it on a web server anyway.
Calling the Translation API
Here is a copy of the HTML file I used. I made the UI simple so it didn't take up much space. You just enter some text in one of the supported languages and select a language to translate to. Clicking "Translate" replaces the text you entered with the translated text. It doesn't support every language translation pair. So you can't to Chinese to Arabic yet. The supported pairs are here. The nice thing about the API is that it auto detects the source text language so you don't have to select "Spanish to English"
Invoking the Google API is really simple. Just call translate with the source, leave the source language blank to auto-detect, the target language code and the return function.
google.load("language", "1");
function translate() {
var source = document.getElementById("source");
var target = document.getElementById("target");
google.language.translate(source.innerHTML, "", target.value, function(result) {
if (!result.error) {
var source = document.getElementById("source");
source.innerHTML = result.translation;
}
else {
alert(result.message);
}
});
}
Now you can pretend to be a cultured international business man/woman and easily throw a few foreign words into the conversation. Tres Cool.
In the future I might try integrating the API into the Office Communicator Web client because I think I'd be able to do real-time translation of conversations pretty easily. It's currently #11 on my side-project list.