Reputation: 41
I am trying to put second language on my webpage. I decided to use different files for different languages told apart by path - language/pl/projects.ln
contains Polish text, language/en/projects.ln
- English. Those extensions are just to tell language files from other, the content is simple php:
$lang["desc"]["fabrics"]["title"] = "MATERIAŁY";
$lang["desc"]["fabrics"]["short_text"] = "Jakiś tam tekst na temat materiałów";
$lang["desc"]["services"]["title"] = "USŁUGI";
$lang["desc"]["services"]["short_text"] = "Jakiś tam tekst na temat usłóg";
And then on the index page I use it like so:
session_start();
if (isset($_SESSION["lang"])) {
$language = $_SESSION["lang"];
} else {
$language = "pl";
}
include_once("language/$language/projects.ln");
print $lang["desc"]["fabrics"]["title"];
The problem is that if the session variable is not set everything works fine and array item content is displayed but once I change and set $_SESSION["lang"]
nothing is displayed. I tested if the include itself works as it should by putting print "sth";
at the beginning of projects.ln file and that works all right both with $_SESSION["lang"]
set and unset.
Please help.
Upvotes: 1
Views: 80
Reputation: 41
Session starts fine and accidentally I managed to fix it.
I renamed $_SESSION['lang']
to $_SESSION['curr_lang']
and it now works allright. It seams like it didn't like the array and session variable having the same name (?).
Upvotes: 0
Reputation: 19612
Can you tell us what does this one output:
if(session_start()) {
echo SID, '<br/>';
if(isset($_SESSION['lang'])) {
echo 'lang = "',$_SESSION['lang'], '"';
}
}
Upvotes: 1