Page 1 of 1
How to add multi-language support to a website
Posted: Mon Aug 10, 2009 8:20 am
by sathyan
Hi All
How can i develop diffrent language versions for the website
this site is in two languages arabic and english as well. As the user select a language .... he should get the site in the selected language. Is it possible using Php.. Is there any specific function supported in PHP to implement this...??
plz help me...
thanx in advanc..........
Re: How to add multi-language support to a website
Posted: Mon Aug 10, 2009 8:32 am
by Swift-R
It's easy, you can do this by using cookies. For example, if there is no cookie set (mysite_language, for example), then all queries will search the english tables in the database, else it will search the tables for the specified language in the cookie.
As for the user selecting the desired language, just make two flag buttons redirecting to a php page which change or add a cookie value, like this:
language_selector.php
Code: Select all
<?php
$language = $_GET['language'];
setcookie ( "mysite_language", $language, time ( ) - 31536000, "/" ) ;
echo 'Language Set!'; // You can do a java redirect to your page here.
?>
And the link in those flags are like this:
Code: Select all
<a href="language_selector.php?language=arabic"><img src="arabic_flag.gif" /></a>
<a href="language_selector.php?language=english"><img src="english_flag.gif" /></a>
Then, to read the cookie:
Code: Select all
<?php
$language = isset ( $_COOKIE['mysite_language'] ) ? $_COOKIE['mysite_language'] : 'english';
// And then the queries
$query = mysql_query ( "SELECT * FROM table WHERE language=" . $language ) ;
?>