How to add multi-language support to a website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sathyan
Forum Newbie
Posts: 9
Joined: Thu Aug 06, 2009 12:35 am

How to add multi-language support to a website

Post 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..........
Swift-R
Forum Newbie
Posts: 2
Joined: Mon Aug 10, 2009 8:04 am

Re: How to add multi-language support to a website

Post 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 ) ;
 
?>
Post Reply