How to Add Google Translation to Your Website or Blog Using PHP
By publishing in only one language you leave out many users and potential clients. According to WorldLingo, a website translation company, around 65% of people on the web speak a language other than English.
To publish in other languages I use Google's Language Tools. Google offers excellent and free one click translation from English
to Arabic, Bulgarian, Chinese, Croatian, Czech, Danish, Dutch, Finnish, French, German, Greek, Hindi, Italian, Japanese, Korean, Norwegian, Polish, Portuguese, Romanian, Russian, Spanish, and Swedish. Google translates the text and then presents the page with the correct formatting
for that language, such as right to left text.
Unfortunately, Google does not offer a way to integrate it's translation service within your site. WorldLingo and AltaVista do, but it either costs money (WorldLingo starts at $40 a month) or requires you to display their rather rather large, preformatted logo. However, with
a little bit of PHP you can embed Google translation into all of your pages simply by copying and pasting some code. PHP and (X)HTML is the most elegant solution, as it's entirely independent the end-users' browser settings. You need to have PHP installed on your server for this to work.
Translation Option One: Flags Ver. 2.0
Below is the the flag based version, I believe these are the most politically correct versions.
Open up the section below and copy and paste the code into your website to use the flag translation used above:
Click to view code
<!-- Begin Google Translation: Flag Version 2.0 -->
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Car" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/ar.png" alt="العربية" title="ترجمة الى العربية" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cbg" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/bg.png" alt="Български" title="Превод на български" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Czh-CN" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/zh.png" alt="简化字" title="翻译,以简体中文" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Czh-TW" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/tw.png" alt="正體字" title="翻譯,以中國傳統" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Chr" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/hr.png" alt="Hrvatski" title="Prevedi na hrvatski" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Ccs" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/cs.png" alt="čeština" title="Přeložit do češtiny" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cda" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/da.png" alt="Dansk" title="Oversæt til dansk" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cnl" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/nl.png" alt="Nederlands" title="Vertaal naar Nederlands" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cfi" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/fi.png" alt="Suomi" title="Muunna suomi" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cfr" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/fr.png" alt="Français" title="Traduire en Français" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cde" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/de.png" alt="Deutsch" title="Übersetze auf Deutsch" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cel" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/el.png" alt="ελληνικά" title="Μεταφράστε στα ελληνικά" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Chi" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/hi.png" alt="हिन्दी" title="हिन्दी अनुवाद करने के लिए" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cit" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/it.png" alt="Italiano" title="Traduci in italiano" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cja" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/ja.png" alt="日本語" title="を日本語に翻訳します" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cko" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/ko.png" alt="한국말" title="한국의 번역합니다" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cno" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/no.png" alt="Norsk" title="Oversett til norsk" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cpl" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/pl.png" alt="Polski" title="Tłumaczenie na Polski" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cpt" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/pt.png" alt="Português" title="Traduzir para Português" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cro" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/ro.png" alt="Români" title="Traduceţi la români" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cru" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/ru.png" alt="Русский" title="Перевести на русский язык" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Ces" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/es.png" alt="Español" title="Traducir al español" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Csv" rel="nofollow">
<img style="border: solid 1px #c8c8c8;" src="http://donutey.com/images/flag/sv.png" alt="Svenska" title="Översätt till svenska" /></a>
<a href="http://www.donutey.com/translation.php"><span style="cursor:help"><img src="http://www.donutey.com/images/re.png" style="border: solid 1px #c8c8c8;" width="30" height="20" alt="Learn More" title="Click to Learn More About Translation"/></span></a>
<!-- Add Translation to Your Site at http://donutey.com/translation.php -->
Translation Option Two: Images Ver. 1.5
Note: This will be updated soon to the newer version with more languages
Below is the image-based version. The included images have the word for that respective language on them. Many of the characters in these languages are incompatible with the standard character set of most users. Using an image of the word will make sure that the word will show up correctly to the user. It's also arguably more politically correct, rather than associating a particular flag with a language.
Copy and paste the code below to use language images translation service demonstrated above:
Click to view code
<!-- Begin Google Translation: Languages Version 1.5 -->
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cde" rel="nofollow">
<img src="http://donutey.com/images/lang/deutsch.gif" alt="Deutsch" title="In Deutschen übersetzen" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Ces" rel="nofollow">
<img src="http://donutey.com/images/lang/espanol.gif" alt="Espanol" title="Traducir a español" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cfr" rel="nofollow">
<img src="http://donutey.com/images/lang/francais.gif" alt="Francais" title="Traduire en Français" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cit" rel="nofollow">
<img src="http://donutey.com/images/lang/italiano.gif" alt="Italiano" title="Tradurre in Italiano" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cpt" rel="nofollow">
<img src="http://donutey.com/images/lang/portugues.gif" alt="Portugues" title="Traduzir no português" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cru" rel="nofollow">
<img src="http://donutey.com/images/lang/russian.gif" alt="Russian" title="ßõрõòõôøтõ ýð руÑÂÑÂúøù ÑÂ÷ыú." /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Car" rel="nofollow">
<img src="http://donutey.com/images/lang/arabic.gif" alt="Arabic" title="ترجمة الى العربية" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cja" rel="nofollow">
<img src="http://donutey.com/images/lang/japanese.gif" alt="Japanese" title="日本語ã«翻訳ã—ãªã•ã„" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cko" rel="nofollow">
<img src="http://donutey.com/images/lang/korean.gif" alt="Korean" title="ÕœêµÂ어로 번ì—ÂÕ˜ì‹Â시오" /></a>
<a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Czh-CN" rel="nofollow">
<img src="http://donutey.com/images/lang/simplifiedchinese.gif" alt="Simplified Chinese" title="翻译æˆÂ简体ä¸Âæ–‡" /></a>
<!-- Add Translation to Your Site at http://donutey.com/translation.php -->
Translation Option Three: Text Links Ver. 2.0
Below is the text-link version, it produces links that appear like those below. They are unstyled, so when they are placed on your site they will assume the link style for your site. The disadvantage of these non-image based links is that Google tends to translate them so it can sometimes look messy.
العربية
Български
简化字
正體字
Hrvatski
Česky
Dansk
Nederlands
Suomi
Français
Deutsch
Eλληνικά
हिन्दी
Italiano
日本語
한국말
Norsk
Polski
Português
Români
Русский
Español
Svenska
Copy and paste the code below into your website to use the text link style demonstrated above:
Click to view code
<!-- Begin Google Translation: Text Links Version 2.0 -->
<abbr title="ترجمة الى العربية"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Car" rel="nofollow">العربية</a></abbr>
<abbr title="Превод на български"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cbg" rel="nofollow">Български</a></abbr>
<abbr title="翻译,以简体中文"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Czh-CN" rel="nofollow">简化字</a></abbr>
<abbr title="翻譯,以中國傳統"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Czh-TW" rel="nofollow">正體字</a></abbr>
<abbr title="Prevedi na hrvatski"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Chr" rel="nofollow">Hrvatski</a></abbr>
<abbr title="Přeložit do češtiny"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Ccs" rel="nofollow">Česky</a></abbr>
<abbr title="Oversæt til dansk"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cda" rel="nofollow">Dansk</a></abbr>
<abbr title="Vertaal naar Nederlands"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cnl" rel="nofollow">Nederlands</a></abbr>
<abbr title="Muunna suomi"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cfi" rel="nofollow">Suomi</a></abbr>
<abbr title="Traduire en Français"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cfr" rel="nofollow">Français</a></abbr>
<abbr title="Übersetze auf Deutsch"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cde" rel="nofollow">Deutsch</a></abbr>
<abbr title="Μεταφράστε στα ελληνικά"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cel" rel="nofollow">Eλληνικά</a></abbr>
<abbr title="हिन्दी अनुवाद करने के लिए"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Chi" rel="nofollow">हिन्दी</a></abbr>
<abbr title="Traduci in italiano"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cit" rel="nofollow">Italiano</a></abbr>
<abbr title="を日本語に翻訳します"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cja" rel="nofollow">日本語</a></abbr>
<abbr title="한국의 번역합니다"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cko" rel="nofollow">한국말</a></abbr>
<abbr title="Oversett til norsk"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cno" rel="nofollow">Norsk</a></abbr>
<abbr title="Tłumaczenie na Polski"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cpl" rel="nofollow">Polski</a></abbr>
<abbr title="Traduzir para Português"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cpt" rel="nofollow">Português</a></abbr>
<abbr title="Traduceţi la români"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cro" rel="nofollow">Români</a></abbr>
<abbr title="Перевести на русский язык"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Cru" rel="nofollow">Русский</a></abbr>
<abbr title="Traducir al español"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Ces" rel="nofollow">Español</a></abbr>
<abbr title="Översätt till svenska"><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&langpair=en%7Csv" rel="nofollow">Svenska</a></abbr>
<!-- Add Translation to Your Site at http://donutey.com/translation.php -->
Conclusion and Examples
You're free to hotlink to images as long as the bandwidth is less than 10MB a month. Otherwise, please download the images and make the references in the code go to your site
instead of Donutey.
I've been using the image based version on my site, located in the footer below, for the past few months and I've been very satisfied. Another example of the second translation option can be found at the East Hills Elementary website.
Kevin C. July 18th 2006 kcas88@gmail.com
Last Updated Jul. 12th 2008
<Back to Translation Portal
『I know of only one bird - the parrot - that talks; and it can't fly very high.』 - Wilbur Wright, declining to make a speech in 1908