How to include different language

I was asking in previous post about folder structure and now cames out a question about organizing languages structure. I would be really happy if anybody can comment if the following is a common way for language versions.

settings.php
if(empty($SESSION[lang])){
include_once ‘/languages/lang_en.php’;
}else{
include_once '/languages/lang
’.$_SESSION[lang].‘.php’;
}

lang_en.php
$profileUpdated=“Profile has been sucesfully changed”;
$writeProfileInfo=“Please submit your information”;
$needFirstName=“Missing first name”;
$needFirstName=“Missing last name”;
$from[profile]=“from”;
$from[home]=“cooming from”;

lang_si.php
$profileUpdated=“Profil je bil uspešno spremenjen”;
$writeProfileInfo=“Prosimo izpolnite vaš profil”;
$needFirstName=“Manjka ime”;
$needFirstName=“Manjka priimek”;
$from[profile]=“iz”;
$from[home]=“prihaja iz”;

profile.php


<?
include_once 'settings.php'
if(isset($_POST[submit])){
  if(empty($_POST[firstName])){
    $error[]=$needFirstName;
  }elseif(empty($_POST[lastName])){
    $error[]=$needLastName;
  }else{
    $msg=$profileUpdated;
  }
}
//...
?>
<html>
<body>
<div id="msg">
  <? 
  if(isset($msg)){
    echo $msg;
  }
  ?>
</div>
<div id="profile">
  <?
  echo $writeProfileInfo;
  echo '<br />';
  echo $firstName;
  echo '<input type="text" name="firstName" />';
  echo '<br />';
  ?>
</div>
<div id="friends">
  <?
  echo $friendFullName[1]." ".$from[profile]." ".$friendLocation[1];
  ?>
</div>
</body>
</html>

when do you set the sessions for language selection? Is there a button on the front page say for example, images of flags and each button sets the session for the language? I think this is ok.

Probably I will put to anchor to a flag image and put the following lines on top:


if(isset($_GET[lang]){
  $lang = $_GET[lang];
  switch($lang){
    case "en":
      $_SESSION[lang]="en";
      break;
    case "si":
      $_SESSION[lang]="si";
      break;
    default:
      $_SESSION[lang]="en";
      break;    
  }
}

and this inside html


$parms='';
foreach ($_GET as $name=>$val) {
  if ($parms!='') $parms.='&';
  $parms.=$name.'='.$val;     
}
<a href="<? echo $_SERVER['PHP_SELF'].$parms."&lang=en"; ?>"><img src="/images/english.gif"></a>

And I will prefer use array, so I will use $LANG[firstName] instead of $firstName.

I would have put everything into a single array or object, so you only have one global variable for your language strings - maybe you will use them in a function.

$lang['profileUpdated'] = 'Profile has been sucesfully changed';
$lang['writeProfileInfo'] = 'Please submit your information';
$lang['needFirstName'] = 'Missing first name';
$lang['needLastName'] = 'Missing last name';
$lang['from']['profile'] = 'from';
$lang['from']['home'] = 'cooming from';

EDIT:

That seems a little complicated, if you want to reuse that code for even more languages. Just go along with your $lang-variable (or $_SESSION[‘lang’]) and check whether the language files exists - if not load the default language…