Latest in our website
News:
- Pharchiver
- Heretic Mansion
- Loss of Motivation
Scripts:
- Simplicity oF Upload 1.3.2
Tips:
- Dynamically Fetching Data without Refreshing (XMLHttpRequest)
- Running a Multilingual website
- How can I limit the number of rows returned by MySQL? (Pagination)

Login
login to access your private areas.

Remember me:

Forget password? Use the reminder.
Or
Not registered? Sign up now!

September
Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30  

Published in Wednesday 21st 2004f April, 2004 at 08:21 PM By Saleh Jamal
 
this can be done via langauge files!
you may want to have a folder named 'languages' ,for example, and in it language files e.g. english.lng, arabic.lng, dutch.lng ...etc
these file will have variables that contains your text ,, like this:


PHP Code:
<?PHP
//note that you have to open php tags since it's not a php extension file ! 
$txt['main_welcome'] = 'Hi there !'
$txt['main_login'] = 'Please login!'
//etc ..
?>


of course you can change the names of the variables as you like ..
but it's preferable to use file name's inastead of just $txt, because when your site becomes large, you will reach 1000 which can be very annoying ! I ran into this problem and reached $txt[1004]!!
so instead ,as I said, call the vars with the file name like this:

PHP Code:
<?PHP
//main.php variables..
$main['welcome']='Welcome visitor';
$main['whatever']='whatever!';

//profile.php text variable..
$profile['posts']='Number of posts';
$profile['username']='Username:';

//and so on..
?>



now in all your script .. hava a function that will check the user langauge and include() the requested langauge file by user ,,
of course you have to use session or cookies for that !

maybe an intro page to let users choose their language or dropdown menu ,,
anyway here is a function that will check language :

PHP Code:
<?PHP
function check_lang() { 
//make sure that we have a language selected by using session .. 
  
if (!isset($_SESSION['lang'])) { 
  
/* you can either show error message and terminate script 
    die('No language was selected! please go back and choose a langauge!');*/ 
  //or set a default language 
    
$lang 'english'
  } else { 
    
$lang $_SESSION['lang']; 
  } 

//directory name 
  
$dir 'languages'

//no we return the langauge wanted ! 
//Returned String Format: dirname/filename.ext 
  
return "$dir/$lang.lng"

?>


now in your script, this is how you use text from langauge files..


PHP Code:
<?PHP
//this function will check user language and return the file name to be included .. 
$lang check_lang();
include_once(
$lang); 

//now this is how you print text 
echo $txt['main_welcome']; 
?>



so no matter what was the language the text will appear in its correct place ;)

but one note, all langauge files MUST have the same varibles names !!
 

Saleh Jamal