18. Dezember 2003

[ English ]

Adding Machine-Translation to your Weblog

At the top right-hand corner of my Weblog and every permalinked Individual Archive page, there are some flags which translate the page when you click them. Lilia Efimova asked me to explain how they work, so that's what I'll do. (Actually she asked me several times already, so I better get going.)

The flags at the top-right trigger two different machine-translation services: Google and Worldlingo. As most of my Weblog-Entries are in German, I let the service translate from German into the language of the country of which the flag is shown. (So as you will have guessed by now it does not make much sense clicking one of the flags from this page. To see it in action surf to a German entry first.)

I use Google to translate into English and French and Worldlingo for all the other languages: Italian, Spanish, Portuguese, Dutch, Greek, Chinese (simplified and traditional), Japanese and Korean.

If your source language is English, other combinations are possible. Here is a table that shows language-combinations of different machine-translation services.

To add the translation to your site, first decide which language combinations you want to offer.

Then how do you add the code to your site? For Google, this is pretty straight-forward: If you surf to Google's language Tools-Page you can enter a URL (the URL of your blog for example), select the approriate language combination, submit the form and see the URL in your browser's navigation bar. In my case, for a translation of my other Website from German into English it looks like this:

http://translate.google.com/translate?
u=http%3A%2F%2Fwww.roell.net&langpair=de
%7Cen&hl=en&ie=UTF-8&oe=UTF-8&safe=off&
c2coff=1&prev=%2Flanguage_tools

(Note that I have added a manual linebreak after the "?", after "langpair=de" and after "safe=off&" to let the code display with horizontal scrolling here. In your code all lines should be joined together of course.)

Of course this is only a static URL that translates exactly the page that you have specified. You could add a link like that to your blog's homepage. But this won't be useful for the readers of your other pages, for example your archive pages to which your permalinks probably point to.

To add translation to every page you need to add the translation-code to your template and make it dynamically include the URL of the page from which it is invoked. There are several ways to do it. I use an SSI (which may only work on your server if you rename your pages so that they end in .shtml) and the code

<!--#echo var="HTTP_HOST"--><!--#echo var="DOCUMENT_URI"-->
to pass the page's URL to the translator. It may work equally well in PHP. (But as I don't know PHP very well, you'll have to figure it out for yourself or wait for a helpful comment on this entry which will surely appear 20 seconds after I post it.)

For the above example (Google-Translation from German into English) I end up with

<a href="http://translate.google.com/translate?
u=<!--#echo var="HTTP_HOST"--><!--#echo var="DOCUMENT_URI"-->&langpair=de%7Cen&hl=en&prev=%2Flanguage_tools"> (an image here) </a>

(Same disclaimer applies)

Got that? (Before you go any further you should try that and see if it works.)

When using worldlingo, things get more complicated. Worldlingo uses a weird system of passing parameters to its translation-script. I have experimented with it for several hours and I have no idea why it works exactly the way it does (so please don't ask "why is this so complicated" - I just don't know. This works for me, maybe there are better ways, I don't know. And I'm not geeky enough that I want to find out.). Here is what I ended up with. My example is for a translation from German to Japanese.

<a href="http://www.worldlingo.com/wl/translate/de/translation.html?
wl_lp=DE-ja&wl_fl=0&wl_rurl=<!--#echo var="HTTP_HOST"--><!--#echo var="DOCUMENT_URI"-->&wl_url=<!--#echo var="HTTP_HOST"--><!--#echo var="DOCUMENT_URI"-->&wlg_table=-3"> (image here) </a>

(Again: Code continues directly after the "?". No linebreak, no space there.)

I have marked the parts that you have to change to cope for different language combinations. You may also want to change the "de"-part in the first part of the URL into "en" if you want the translator itself to "speak" English instead of German.

Worldlingo also offers the possibility to select a specific vocabulary for a translation. If your Weblog is about Technology, Medicine or Metallurgy (?) then you may want to play around with the script a little. You can see how it works when you manually enter a page's URL, have it translated and then translate it again by clicking the "Translate"-Button at the top of the screen.

I have not tried other translation services besides Google and Worldlingo as they don't offer translations from German. But if you try them out, be sure to let me know if they work!

Any questions?

[Update 13.01.04] Taran Rampersad explains how to add Google translation to a MovableType blog

[05.01.05] Drupal and Automatic Translations - KnowProSE.com and OpenDepth.com now Enabled. - KnowProSE.com

Trackbacks sind Links von anderen Weblogs auf diesen Eintrag.

Martin Roell shares a secret of adding machine-translation to your weblog .

Mathemagenic: Adding machine-translation to your weblog (18.12.03 09:14)

Martin Röll: Adding Machine-Translation to your Weblog. Ausrucken! [Das E-Business Weblog]

Der Schockwellenreiter: Hoch die internationale Solidarität (18.12.03 15:15)

After having read Martin Röll's article about Google translated

superBlog: Google Translation (18.12.03 17:44)

Since I've finally updated the navigation at the top - something I'd been meaning to do for some time - the next step is to allow translation into native languages. Fortunately, Martin has already implemented something in his weblog. Das...

KnowProSE: The next step for the Site. (11.01.04 17:41)

Update: I have recently moved all my blog tips category to a new blog dedicated to blogging atProBlogger. I've been reading Unleashing the Idea Virus by Seth Godin this past week or so. I'm really taking my time over it...

LivingRoom >> A space for Life: Viral Blogging (18.11.04 06:06)

 

Great! I'm going to find a way to make it working for my blog. I really believe that it's time to use technologies to make human connections a bit easier.

Btw, in my case the main reason to click on the link when your post pops up in my aggregator is knowing that you have those buttons on each page :)

Lilia am 18.12.03 08:20 #
 

20 seconds are hard to meet at 2 am. ;-) Here's the solution for Apache + PHP.

<a href="http://translate.google.com/translate?u=http://<?= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ?>&langpair=de%7Cen">...

Thiemo Mättig am 18.12.03 10:06 #
 

Danke Martin,
Obwohl ich nicht sehr beeindruckt bin von der Qualität dieser Maschinenuebersetzungen hilft es sicherlich ein wenig mitzubekommen worüber ein Posting denn geht. Ich werde mir überlegen ob ich sowas nicht benutzen kann um meine Holländisch und Deutschsprachigen Posts nicht auch für Anderssprachigen entschliessen kann. Bin mir weniger sicher ob das Sinn hat fürs englische Blog. Vielleicht nach Fr. Sp. und Jap. Naja, food for thought so sagt man.

Danke für die Erläuterung!

Ton Zijlstra am 18.12.03 10:38 #
 

Regarding the PHP/Apache Solution I suggest to use

&langpair=de%7Cen">

Important thing is the usage of urlencode() to encode all the special entities that may occur within a request string, like additional parameters passed to the page you want to have translated.

Apart from that: Your entry finally got me to use google translation for my own page as well. Thanks for the heads-up. ;)

BTW, did you know that "Ha-Ha!" (indicating laughter) is translater into "Hectar-Hectar!"? ;-)

Garvin am 18.12.03 17:47 #
 

Uh, I just saw that my code comments where HTML-interpretet, so once again (hoping that the htmlentities for opening and closing tags are converted):

<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=de%7Cen">...
Garvin am 18.12.03 19:46 #
 

Hi. I think you'll like the translate this page feature that my translator includes. You can see the translator or read more about it. If there are any ideas you've got on how to integrate this more into blogs, I'm all ears.

Btw, my Translation Wizard is a meta-translator. Which is to say that it uses WorldLingo, FreeTranslation, etc. AltaVista's Babelfish, Google, and WorldLingo, among others, are powered by Systran.

Michael Fagan am 18.12.03 21:02 #
 

You are absolutely right, Garvin. Thanks.

Thiemo Mättig am 18.12.03 22:30 #
 

That's very cool, Michael! I have added your translator to my translation-links. (I need to find a better place for it, but until then...)

Martin Röll am 07.01.04 17:39 #
 

Because this entry is attracting far too many spam-comments I am closing the comments on this entry. If you have something to add please email me at martin@roell.net

Martin Roell am 15.04.04 08:30 #