Easy PHP Site Translation

Here’s an easy way to translate your web site using PHP. The idea is to have several files for each language you want to provide. Each one of these files have the name of the ISO code and the txt extension. For this demo I only use the german language as an alternative to the […]

PhpTranslate

Here’s an easy way to translate your web site using PHP. The idea is to have several files for each language you want to provide. Each one of these files have the name of the ISO code and the txt extension. For this demo I only use the german language as an alternative to the default language of the site – english. The content of these files are the words / sentences with their translation in the form:

word=translation

The PHP class provided will parse this file, create an array which maps both word and it’s translation pair. You just need to insert the following in your php code :

$translate = new Translator($outputlanguage);//$outputlanguage: ISO code (example: de,en,...) --> these are the names of each file

$translate->__('word to translate');

An example:

<h2><?php $translate->__('Registration'); ?></h2>

and in your de.txt file we would have:

Registration=Registrierung

View demoDownload source

Previous:
Next:

Tagged with:

Chadking is an absolute geek that rarely leaves the comfort of his 3-screen desk. He is a self taught programmer and is addicted to all possible legal drugs.

View all contributions by

Website: http://tympanus.net/codrops/author/chadking/

Related Articles

CSS Reference

Learn about all important CSS properties from the basics with our extensive and easy-to-read CSS Reference.

It doesn't matter if you are a beginner or intermediate, start learning CSS now.