Hi,
I am trying to create a multilingual site and am having a few problems keeping track of the language the user has selected, using the following at the top of the page at the moment:
// Detect and include correct language
session_start();
// $lang not set
if(!isset($lang)) {
// get language set to browser
$lang = getenv('HTTP_ACCEPT_LANGUAGE');
// get the first two characters of HTTP_ACCEPT_LANGUAGE
$lang = substr($lang,0,2);
// set default language to en
$lang_default = "en";
}
// get $lang variable
$lang = $_GET['lang'];
// make sure $lang file exists
if (is_file("../_lang/index.$lang.php"))
{
// file exists, load language
$_SESSION["lang"] = $lang;
include("../_lang/index.$lang.php");
} else {
// file does not exist, load default language
$_SESSION["lang"] = $lang_default;
include("../_lang/index.$lang_default.php");
}
So when i first load the site it gives me english as my default as my browser headers are set to this.
I then select french and move onto the next page - instead of keeping french, it puts it back to English.
I'm sure this is because I keep resetting the language to english but I am getting confused as to the order of my if statements.
I am using the following links to create the change between languages:
<? if ($_SESSION["lang"]=="en") {
echo"<a href=\"?lang=fr\">";
} else if ($_SESSION["lang"]=="fr") {
echo"<a href=\"?lang=en\">";
} ?>
Really getting muddled now, hopefully someone can put me in the right direction! Thanks.
Chris.