Showing posts with label google. Show all posts
Showing posts with label google. Show all posts

Saturday, September 08, 2007

Auto-translate Resource Bundles using Google Translate

Internationalization is one of the common requirements in web applications. One of the challenges faced by a team is the non-availability of translated resource bundles during development (mostly due to logistical reasons). But it is important to test various scenarios during the application development.

In this post I will present a simple idea which utilizes Google Translate to auto-generate translated Java Resource Bundles for the language of choice. Just send a HTTP GET request with the text to be translated to Google Translate URL and read the translated text by parsing the response. In order to translate an entire resource bundle just pass a source bundle (For example, English) and read each property and write to target language resource bundle file.

Here is the URL for translating "welcome" from English to Spanish http://www.google.com/translate_t?langpair=en|es&text=welcome

Here is a snippet of Java code which utilizes Apache Commons HttpClient library :

String url = "http://www.google.com/translate_t? langpair=en|es&text=";
String text = "welcome";

HttpClient client = new HttpClient();
GetMethod getMethod = new GetMethod(url + text);

client.executeMethod(getMethod);
String xml = getMethod.getResponseBodyAsString();
xml = xml.substring(xml.lastIndexOf("<div id=result_box dir=ltr>"));
String translated_text = xml.substring(27, xml.indexOf("</div>"));
System.out.println(translated_text);

Technorati tags: , , ,

Monday, August 21, 2006

Click-n-Translate: Globalize your blog posts

Translate this post

from

Welcome, Willkommen, Recepción, 歓迎, 환영, 欢迎

With few easy steps and with the technology from Google you can allow your blog posts to be read in any language.

For a demonstration select the language of your choice and click Translate button. If you like Digg This!

To enable this to your blog posts...

Add the following piece of code to your blog posts:

Replace http://venkks.blogspot.com/2006/08/translate-your-...

with your current blog post address.

<form action="http://www.google.com/translate">
<p><font size="-1">&nbsp;&nbsp;

Translate this post<br>&nbsp;&nbsp;<input dir="ltr" type="hidden" size="55" value="http://venkks.blogspot.com/2006/08/translate-your-..." name="u">
<br>&nbsp;&nbsp;<font size="-1">from</font><select name="langpair">

<option value="ende">English to German</option>

<option value="enes">English to Spanish</option>

<option value="enfr">English to French</option>

<option value="enit">English to Italian</option>

<option value="enpt">English to Portuguese</option>

<option value="enar">English to Arabic BETA</option>

<option value="enja">English to Japanese BETA</option><option value="enko">English to Korean BETA</option><option value="enzh-CN">English to Chinese&nbsp;(Simplified) BETA</option><option value="deen" selected>German to English</option><option value="defr">German to French</option><option value="esen">Spanish to English</option><option value="fren">French to English</option><option value="frde">French to German</option><option value="iten">Italian to English</option><option value="pten">Portuguese to English</option><option value="aren">Arabic to English BETA</option><option value="jaen">Japanese to English BETA</option><option value="koen">Korean to English BETA</option><option value="zh-CNen">Chinese&nbsp;(Simplified) to English BETA</option></select><input type="hidden" value="en" name="hl"><input type="hidden" value="UTF8" name="ie"><input type="submit" value="Translate"></p></form>

--- End of Code ---

Courtesy: Google!

Disqus for techtalk