a few words about web development

Google Translate - PHP class for automatic translation

Free text translation for your websites
Edited on 06.03.2012: Unfortunately Google no longer provides free access to their Google Translate API so this class does not work any more. You can still use it as a learning reference on how to use Web APIs.

Here is a very simple in use class to translate any text from one language to another using Google Translate service. The results are cached, so it is quite fast.
It supports all the languages which are available on translate.google.com.
Cache is stored in php files, so you do not need any database at all!

The usage is very simple:

include 'GoogleTranslate.php';
$t = new GoogleTranslate;
$t->inLang = 'en';
$t->outLang = 'de';
echo $t->translate('Hello World');

The above code will display "Hello World" in German.
Code is release under the MIT license, so you can use it even in commercial projects.
Enjoy and please leave a comment!

Comments