1

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.

KotuS
  • 41
  • 5

2 Answers2

1
  1. Can you test the return value of session_start() - if it's false, it failed to start the session.
  2. Is it being called before you output anything to the browser? If headers were already sent and your error_reporting level is too low, you won't even see the error message.
  3. Stupid, but - do you set value of $_SESSION['lang'] to valid value like "en"? Does the English translation load correctly when you use it as default value in else block instead of "pl"?
  4. "Jakiś tam tekst na temat usłóg" -> "usług" :)

Can you tell us what does this one output:

if(session_start()) {
    echo SID, '<br/>';
    if(isset($_SESSION['lang'])) {
        echo 'lang = "',$_SESSION['lang'], '"';
    }
}
eyescream
  • 18,088
  • 2
  • 34
  • 46
0

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 (?).

Kev
  • 118,037
  • 53
  • 300
  • 385
KotuS
  • 41
  • 5