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:
(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
For the above example (Google-Translation from German into English) I end up with
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.
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!
[Update 13.01.04] Taran Rampersad explains how to add Google translation to a MovableType blog