Friday, March 21, 2008

Useful Google Translate Addresses

Translate a web page:

http://www.google.com/translate_c?langpair=LANG1|LANG2&u=URL

Example: http://www.google.com/translate_c?langpair=it|en&u=http://www.corriere.it/ translates Corriere della Sera's homepage from Italian into English.


Translate a web page into English (the input language is detected automatically):

http://www.google.com/translate_c?langpair=en&u=URL

Example: http://www.google.com/translate_c?langpair=en&u=http://www.corriere.it/ translates Corriere della Sera's homepage from Italian into English, but without explicitly mentioning that the web page is written in Italian.


Use Google Translate as a proxy:

http://www.google.com/translate_c?langpair=LANG1|LANG2&u=URL

You basically want to read the page in its initial language, but loaded from Google's servers. LANG2 should be the code for your web page's language, while LANG1 can be any supported language so that LANG1|LANG2 is a valid language pair.

Example: http://www.google.com/translate_c?langpair=fr|en&u=http://craigslist.org shows Craigslist's home page using Google Translate as a way to bypass security restrictions.


Translate a text:

http://www.google.com/translate_t?langpair=LANG1|LANG2&text=TEXT

Example: http://www.google.com/translate_t?langpair=en|es&text=Hello, world! translates "Hello, world!" from English into Spanish.


Notes:

1. the language pairs are listed in this FAQ, while the language codes are included in this long list.

2. To disable Google Translate's annoying tooltips that show the original text, block this JavaScript file: http://209.85.135.104/translate_c.js, for example by adding a new rule in Adblock Plus for Firefox or by using Opera's content blocker.

Labels:

  7 comments ( Post a comment )
I tried to read the Italian translated to English and it was awful.
I sometimes use Gtrans as a proxy to bypass corporate filters, (xlate English to Spanish, for example, then mouseover to see orginal). Would be more useful as proxy if could fake the xlate - translate English to English ...
Also use the FF add-on to xlate a page I'm viewing.
Google doesn't allow you to translate from English to English anymore, but you can always pretend that you're translating from a different language to English (for example, from Spanish to English).
is there a way to just return an xml document for the "Translate a Text" example.

I'm wondering this, as I'm curious if google's translate tool can be used by sites to translate text.

at the moment the work around is
@file_get_contents("http://www.google.com/translate_t?langpair=en|es&text=Hello, world!")

preg_match('/< d i v id=result_box dir=ltr>(.*?)<\/ d i v >/', $in, $out);

or there is a good tool out there already for what I am after?
@feeble:
You no longer need to scrape the text. Use the translation API for JavaScript. "With the AJAX Language API, you can translate and detect the language of blocks of text within a webpage using only Javascript."
@ionut Alex Chitu:
I have been looking over the "translation API for JavaScript"

Its not perfect, but its pretty close.

Thank you.