Drupal and Automatic Translations - KnowProSE.com and OpenDepth.com now Enabled.

A lot has happened since I wrote, 'Drupal Translations: The Progress, The Fault.

See Below For Updates

In fact, if you look at the top of this page - or any other page on KnowProSE.com and OpenDepth.com - you'll see little flags. And those little flags, when clicked, start a chain of events which causes the Google Language Tools to translate the page for you.

Automatic translation has limitations, but a lack of it has more limitations. While I believe that human translation using trackbacks is best, I don't speak all of those languages. And when dealing with open content licensing (as I use), someone who speaks the language the automatic translation goes to can translate the work and link back to the original. This is pretty important on the internet, though a lot of people who visit these pages don't understand why it's so important. The ability is obviously not for them - but for the people who can't read English.

Still, it reminded me of the days when Gene Watson and I would use automatic translation tools in the 1990s to write emails to each other - first in English, translate to another language, then translate to another language. We were thoroughly amused, sort of like a twisted Monty Python skit via email. If you ever mete Gene, ask him about 'Excuse me, do I have cheese on my neck'.

How Did You Do It?

I'm glad you asked. First of all, I decided to solve the problem. Then I tracked through the Drupal code, and even tried the Internationalization module for Drupal. It works, but would require me to have to rewrite all the content in different languages - something that doesn't seem very practical to me. It is, however, quite practical for a multilingual website where authors on the site write in different languages. Definitely useful. Jose A. Reyero deserves a lot of credit for making il8n possible.

So what I decided to do was to simply hack the Drupal themes I use to do what I wanted to.

Hacking The Chameleon Theme

Having never seriously edited a Drupal theme before, I was nervous for approximately 3 microseconds and then I piled into it - first working on the translation for OpenDepth.com. The Chameleon theme required some tweaking of both the theme file and the Cascade Style Sheet (CSS) file. I added this code to the chameleon.theme file (for those who can't stand CODE, skip past the blue and continue reading):


$output .= " <a href =\"http://translate.google.com/translate?u=http%3A%2F%2Fwww.yoursite.com%2Fnode%2F". $node->nid. "&langpair=en%7Ces&hl=en&ie=UTF-8&oe=UTF-8&prev=%2Flanguage_tools\"><img src =\"/images/flag_es.gif\" width =\"14\" height =\"9\"></a> ";

$output .= " <a href =\"http://translate.google.com/translate?u=http%3A%2F%2Fwww.yoursite.com%2Fnode%2F". $node->nid. "&langpair=en%7Cfr&hl=en&ie=UTF-8&oe=UTF-8&prev=%2Flanguage_tools\"><img src =\"/images/flag_fr.gif\" width =\"14\" height =\"9\"></a> ";

$output .= " <a href =\"http://translate.google.com/translate?u=http%3A%2F%2Fwww.yoursite.com%2Fnode%2F". $node->nid. "&langpair=en%7Cpt&hl=en&ie=UTF-8&oe=UTF-8&prev=%2Flanguage_tools\"><img src =\"/images/flag_po.gif\" width =\"14\" height =\"9\"></a> ";

$output .= " <a href =\"http://translate.google.com/translate?u=http%3A%2F%2Fwww.yoursite.com%2Fnode%2F". $node->nid. "&langpair=en%7Cde&hl=en&ie=UTF-8&oe=UTF-8&prev=%2Flanguage_tools\"><img src =\"/images/flag_gr.gif\" width =\"14\" height =\"9\"></a> ";

$output .= " <a href =\"http://translate.google.com/translate?u=http%3A%2F%2Fwww.yoursite.com%2Fnode%2F". $node->nid. "&langpair=en%7Cja&hl=en&ie=UTF-8&oe=UTF-8&prev=%2Flanguage_tools\"><img src =\"/images/flag_jp.gif\" width =\"14\" height =\"9\"></a> ";

$output .= " <a href =\"http://translate.google.com/translate?u=http%3A%2F%2Fwww.yoursite.com%2Fnode%2F". $node->nid. "&langpair=en%7Cko&hl=en&ie=UTF-8&oe=UTF-8&prev=%2Flanguage_tools\"><img src =\"/images/flag_ko.gif\" width =\"14\" height =\"9\"></a> ";

$output .= " <a href =\"http://translate.google.com/translate?u=http%3A%2F%2Fwww.yoursite.com%2Fnode%2F". $node->nid. "&langpair=en%7Czh-CN&hl=en&ie=UTF-8&oe=UTF-8&prev=%2Flanguage_tools\"><img src =\"/images/flag_ch.gif\" width =\"12\" height =\"8\"></a></h2>\n";


If you use it, you might want to replace 'yoursite.com' with... your site's address, otherwise you will get interesting results which have nothing to do with your site.

You'll also have to add this to the style.css file:


h2.translation {
background-color: #fff;
border: solid 1px #888;
margin-top: 1px;
height: 6px;
margin: 0em 0em;
font-size: xx-small;
line-height: 8px;
}

If that's too difficult, download the TAR or ZIP file named chamtranslate below. You *will* need the flags as well, and those are all zipped as well in the self-explanatory name, flag, as ZIP and TAR. Decompress the files - the flag files belong in an '/images' directory; the other files are to replace the ones you have now in your /themes/chameleon for the .theme file, and themes/chameleon/marvin for the styles.css. Backing up files before doing this is common sense, but if you fail that test and something goes wrong - just re-download the original theme and start over.

The Slurpee Theme

The DrupalSlurpee theme was easy to hack. I put the same code from chameleon.themeslurpee.theme - and you can download that below as well. Just replace your old Slurpee.theme file with this one.

Other Themes

The same code, properly placed, should work in all other themes. I've worked on the two that I use, and made the code available to everyone. Personally, I'd like to see it as an option in all future Drupal themes - it's not hard. In fact, once I made up my mind, it took me less than 2 hours to do everything and test it out.

So if your theme needs the hack, well - you can do it yourself, you can beg someone to do it, or you can pay someone to do it.

Problems

Of course, there are problems with the automatic translations as I mentioned above. No machine translation is 100% accurate. But another problem may crop up if Google changes any of it's links, in which case the code will have to be adapted. The other problem is that the samples above only work from English to other languages - the code will have to be adapted (just the links) for it to work from another language, such as Spanish, to English.

Conclusion

I wish I had simply hacked this out before, instead of getting caught up in other things. It's imperfect, but it's better than no translation. Now, many more people around the world can have an idea - hopefully - of what I'm rambling on about, and will not require leaving this site to get an automatic translation done.

If you do use these hacks, a bit of credit is welcome. Drop a link back here - especially if you adapt another theme that someone else can use. :-)

UPDATES

Interlaced theme hacked for OpenDepth.com; interlaced.zip has the hacked interlaced theme file for translations (4.6.0).

January 18th, 2006

Dave A. Chakrabarti has successfully created a Block method for doing the same thing.

AttachmentSize
chamtranslate.tar10 KB
chamtranslate.zip2.7 KB
slurpee.theme12.4 KB
flag.tar20 KB
flag.zip4.93 KB
interlaced.zip1.97 KB

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.
  • Easily link to terms in various wikis. For help, see <a href="/interwiki/3">interwiki</a>.

More information about formatting options

CAPTCHA
Sorry, but you are required to have some math knowledge to use the internet.
1 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Syndicate content