Thursday, November 27, 2008

using AJAX to dynamically translate a report

I decided to push the AJAX integration a little bit further...
Using jQuery and Google AJAX Language API, I was able to translate in "real time" a report. For my example, I decided to translate the records of a table containing the different states of the USA. I realize that this data is not the best for translation demonstration because many words are almost the same no matter what is the spoken language. To have better results, translate the data to Arabic, Chinese, Japanese or Korean.

You can try a working example of the Dynamic Translation w/ Google AJAX Language API demo.

1) Report (Region Definition)
SELECT     st
,initcap(state_name) AS state_name_en
,initcap(state_name) AS state_name
FROM demo_states

N.B. I had to use the initcap function on my data. Google translation engine is case sensitive. (I need to find more documentation to help with this issue.)

2) Report (Column Attributes)
Column Formatting > CSS Class: translate_src

Column Heading : State Name (<span id="src">english</span>)
Column Formatting > CSS Class: translate_dst

3) Language Selection
I created a Select List item (P35_DST) inside my region "Translate". The options of this Select List are added dynamically when the "init_language_selection_tool" function is called.

4) JavaScript code

<script src=""></script>
// Load jQuery
google.load("jquery", "1.2.6", {uncompressed:false});

// Load Google AJAX Language API
google.load("language", "1");
function translate_report(pFrom, pTo) {
if (pTo != '-1' && pTo != "") {
var l_translation = $(this);
google.language.translate(l_translation.text(), pFrom, pTo, function(result) {
if (!result.error) {
$s('src',$('#P35_DST option:selected').text());

//overwrite existing $a_report function
function $a_report(G,D,F,C,A){
var B=$x("report_"+G+"_catch");"report_"+G+"_catch_old";
var E="p="+$v("pFlowId")+":"+$v("pFlowStepId")+":"+$v("pInstance")+":FLOW_PPR_OUTPUT_R"+G+"_";


var H=new htmldb_Get(null,null,null,null,null,"f",E);
var I=H.get();



function init_language_selection_tool() {
var dst = $x('P35_DST');
var i=0;
for (l in google.language.Languages) {
var lng = l.toLowerCase();
var lngCode = google.language.Languages[l];
if (google.language.isTranslatable(lngCode)) {
dst.options.add(new Option(lng, lngCode));

function init_language_selection_event() {

$().ready(function() {

Web 2.0 offers lots of possibilities. Gotta try them all! ;)
I speak French and English. I would like to have feedback about the translation of the other languages.


Roel said...

This is really nice! Although the example of US states is not very good I guess, because almost all of them have the same names in other languages. I spotted only one error in the Dutch translation (Georgia is the same in Dutch, "Georgië" is that country at the south of Russia).

Paulo Vale said...

Nice demo.. some mistakes with the Portuguese language, but I guess that it's not your fault ;)

Martin Giffy D'Souza said...

Very impressive! Good way to do some quick translations if necessary.


Louis-Guillaume Carrier-Bédard said...

I would like to see this in a real application. It can be use for a translation application where you can upload an xliff file and do an automated translation process using the user predefined dictionary and Google Translate.
I like this tool: .
I think it should use my technique to help the translation process.

Patrick Wolf said...

Really nice!


technical translation said...

Nice post.I would say that the importance of technical translation being accurate and efficient can indeed not be overstated. Especially in the ever faster moving world of globalized business, successful information and technology transfer within multinational businesses can make the difference between win or lose.