multiple langauge

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
bhanu
Forum Commoner
Posts: 46
Joined: Thu Nov 05, 2009 4:25 am

multiple langauge

Post by bhanu »

HI i want to display multiple langauges in my site,when user visit and he can change language.how to code multiple language for my site using php code.is there any free scripts .please help me...

urgent requirement
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: multiple langauge

Post by JakeJ »

Have you tried google? Try this in the search box: php select language script
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: multiple langauge

Post by pickle »

Basically it works like this: You determine the user's language, then pull strings from that language's file.

Example:

en.lang.inc

Code: Select all

$lang['greeting'] = 'Hello';
$lang['beer'] = 'beer';
es.lang.inc

Code: Select all

$lang['greeting'] = 'Hola';
$lang['beer'] = 'cerveza';
Main page

Code: Select all

//Somehow determine their language.  Either from the headers sent from their browser, a form they've entered, or read from the database from a previous page load;
 
$user_lang = 'en';//just as an example:
 
//include only the language file for the user's file
include $user_lang.'.lang.inc'; 
 
echo $lang['greeting'].' user, would you like a '.$lang['beer'].'?';
A user that's chosen English will get "Hello user, would you like a beer?". A user that's chosen Spanish will get "Hola user, would you like a cerveza?"
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: multiple langauge

Post by JakeJ »

A user that's chosen English will get "Hello user, would you like a beer?". A user that's chosen Spanish will get "Hola user, would you like a cerveza?"
Hold on there! Shouldn't that be: Hola usario, quieres una cerveza? /sarcasm
bhanu
Forum Commoner
Posts: 46
Joined: Thu Nov 05, 2009 4:25 am

Re: multiple langauge

Post by bhanu »

thank you for replies.
Post Reply