How to Add Google Translation to Your Website or Blog Using PHP
Note: Due to repeated abuses, hotlinking to the images is no longer allowed, please download the images and host them on your own server. Sorry for the inconvenience.
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. Please remember to download the images and host them on your own server.
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%3A%2F%2Fdonutey.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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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.<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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. Please remember to download the images and host them on your own server.
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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/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://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/images/lang/simplifiedchinese.gif" alt="Simplified Chinese" title="翻译成简体中文" /></a>
<a href="http://donutey.com/translation.php"><span style="cursor:help"><img src="http://<?php echo urlencode($_SERVER['HTTP_HOST']); ?>/images/re2.png" 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 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
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 Aug. 16th 2008
<Back to Translation Portal
『It has been said that democracy is the worst form of government except all the others that have been tried.』 - Sir Winston Churchill