This short article explains how to quickly and easily add Google Translate functionality to Drupal content without hacking any blocks or the actual content itself. You simply stick it into a page template where it belongs.
But for Google Translate you do not need any keys yet and this is so simple it’s hardly worth the CVS.
The amazing and amazingier all the time Google Translate has already wowed the masses just a few days ago, with “translation as you type” functionality. Just go to http://translate.google.com/# and with the Translate from option set to “Detect language”, and the Translate to option set to English, just typing “¿Cómo te va?” will have the Google gremlins detecting that the sentence is Spanish and already putting in a colloquial “How you doing” in the correctly labeled Spanish to English results area. And as an extra special bonus, there is a speaker icon where you can actually hear the phrase spoken. Impressive.
Well, if you are at all like me, “how can I get some of this good stuff into my Drupal pages”, I hear you saying?
On the left hand side menu, click on “tools and resources” option, check out what it says there and grab the following snippet of code:
Adding this code to any web page will place a drop down Select language menu for the whole page to be immediately translated into any of a zillion languages. You can try it out on the same page.
Now, where do we put this in Drupal?
This Google Translate snippet is ideal for a page template.
Let’s say we only want the Google Translate icon and drop down language selection box to appear on node 2. Go into your current theme and copy page.tpl.php to page-node-2.tpl.php and stick the snippet write before the “print $content” line.
You’ll need to close the php code and open it up again in order to insert pure HTML. (Of course if you want Google Translate to appear on all pages, just modify page.tpl.php.) Here’s the before and after:
print $content; ?>