Hi, yes that works pretty well :D
but I also encountered another problem that I didn't figure out how to solve well (when trying to apply this to multiple pages within my site). I have, say, three pages one.php, two.php and three.php, and all of them now has this language selection bar:
- <div id="navbar"><div class="langbar"><a href="?locale=en_US">English</a> | <a href="?lang=de_DE">Deutsch</a> |
-
<a href="?lang=ru_RU">Русский</a> |
-
<a href="?lang=nb_NO">Bokmål</a> |
-
<a href="?lang=nn_NO">Nynorsk</a></div></div>
I want the user to be able to make a language choice at any point while visiting my site. I read somewhere that storing the variable in a cookie (in a session) was a nice way to do this.
So all my pages should start with:
- <?php session_start();
-
/* and then I tried this */
-
$lang = ( isset ($_GET['lang'] ) ? $_GET['lang'] : 'en_US' );
-
/* store the variable in a cookie so I can remeber it between the pages */
-
$_SESSION['language'] = $lang;
-
setlocale(LC_ALL, $_SESSION['language']);
-
?>
But the problem is that when I browse to another page the URL will change to (i.e.) "www.mywebsite.com/two.php", and the $lang variable is then set to 'en_US'. Hmm.
I know there should be a simple solution to this. Just can't see it, because I'm a noob.
Any help is very much appreciated :D