Entry
Can PHP allow me to translate a website to another language at the click of a button?
May 6th, 2008 09:58
Vishal Sharma, lorenzo campanis, Andy Wright, Onno Benschop, http://bollywoodvideos.indiangamesworld.com
Well, there's no function to translate the website. However The easiest
way to have your website translated in various languages is the following:
1. Create a file for each of your languages (ie. en.php, fr.php, etc)
2. In each of the files you are going to have an array called LANG.
$LANG = array();
3. Give each entry in the array the value you want
$LANG['username'] = "Username"; (for the en.php (english))
$LANG['username'] = "Identifiant"; (for the fr.php (french))
4. Create the links for the language, so english could be your default
but French is done in the following way
<a href="index.php">English</a> |
<a href="index.php?lang=fr">French</a>
Now this ?lang=fr included in the link, is accessible from the global
variable GET, which is an array by default, so when your page loads you
will have to include the appropriate file for your translation(ie en.php
or fr.php). So for this you can do the following:
if($_GET['lang'] == "fr")
include "fr.php"
else
include "en.php"//if nothing is declared or if they messed up the
variable you get english
now to use this in you webpage all you have to do is print out the field
you need. These are the fields you have declared in your lang file(ie.
fr.php)
so now the easy part is to print them out by using:
<?=$LANG['username'];?>
and this will give you what you want! Basically in one click ;)
http://topweddingguide.blogspot.com
http://uniquegiftsideas.blogspot.com/
http://valentinesdaygiftsidea.blogspot.com/