From our sponsor: Dora AI - Generate website ideas to Figma designs in seconds, Near-Perfect on first try.
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
Pingback: Easy PHP Site Translation | Codrops | Coder Online
Pingback: Webby Scripts Easy PHP Site Translation | Codrops
Pingback: abcphp.com
Pingback: uberVU - social comments
Nice post man… thanks a lot… Ill use this one.
I have problems with accents when translating into Spanish. How can I fix it?
TY.
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
Change the UFT-8 all files and everything ready. 1 million thanks for your reply.
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’);
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?
Coollllllllllll