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

Feedback 11

Comments are closed.
  1. Pingback: Easy PHP Site Translation | Codrops | Coder Online

  2. Pingback: Webby Scripts Easy PHP Site Translation | Codrops

  3. Pingback: abcphp.com

  4. Pingback: uberVU - social comments

  5. 2

    I have problems with accents when translating into Spanish. How can I fix it?

    TY.

    • 3

      Hi Pedro,
      I tested it now with several accents and it works fine. Could you tell me an example of a word that doesn’t work for you?
      Cheers

  6. 4

    Change the UFT-8 all files and everything ready. 1 million thanks for your reply.

  7. 5

    Hi,
    I’m sorry to ask but I haven’t been able to successfully place the code below on my php… I’d like to know on which php file I should place it and where exactly!
    Thank you so much!

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

    $translate->__(‘word to translate’);

  8. 6

    Will this keep all other pages in German too? Or just the page you have clicked the flag on? How to keep the whole site German?

Comments are closed.