Forum

Thread tagged as: Question, Problem

multi-language always swapping back on page load

I am using the multi-language solution as given in Docs but unfortunately on new page load it reverts back to german even when english is selected. Here is the code I am using:

Session

session_start();
    $lang = 'de'; // default lang
    switch(perch_get('lang')) {
        case 'en':
            $lang = 'en';
            break;
        case 'de':
            $lang = 'de';
            break;
        // add more cases for language options here...

        default:
            if (isset($_SESSION['lang'])) {
                $lang = $_SESSION['lang'];
            }
            break;
    }
    $_SESSION['lang'] = $lang;

Example of on page code:

<?php if ($lang == 'en'){
            include("inc/lang_en.php");
            } else {
                include("inc/lang_de.php");
            }
        ?>

Anybody had this problem...?

Matthew Owen

Matthew Owen 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the value of lang on the URL at that point?

Hi Drew,

html lang is set to 'de' on each page after doctype.

Is that what you mean?

it skips back to german on each link load.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I mean on the URL - do you have ?lang=de or similar?

ah ok, when a choice is made then ?lang=en is shown. by link click that is then removed.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so that should be fine. What have you done to debug where the value it changes?