Skip to main content
deleted 8 characters in body; edited tags; edited title
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

Is this Language switch too cumbersome?based on parameters and session state

I use this to set language session for navigation. Someone said that this switch is too cumbersome.Why Why? Is there an easier way? I use this to set language session for navigation.

Thanks

$defaultLang = 'it';

if (!empty($_GET["lang"])) {
    switch (strtolower($_GET["lang"])) {
        case "en":
            
            $_SESSION['lang'] = 'gb';
            break;
        case "tr":
            
            $_SESSION['lang'] = 'tr';
            break;
        default:
            
            $_SESSION['lang'] = $defaultLang;
            break;
    }
}

if (empty($_SESSION["lang"])) {
        $_SESSION["lang"] = $defaultLang;
} 

Is this switch too cumbersome?

Someone said that this switch is too cumbersome.Why? Is there an easier way? I use this to set language session for navigation.

Thanks

$defaultLang = 'it';

if (!empty($_GET["lang"])) {
    switch (strtolower($_GET["lang"])) {
        case "en":
            
            $_SESSION['lang'] = 'gb';
            break;
        case "tr":
            
            $_SESSION['lang'] = 'tr';
            break;
        default:
            
            $_SESSION['lang'] = $defaultLang;
            break;
    }
}

if (empty($_SESSION["lang"])) {
        $_SESSION["lang"] = $defaultLang;
} 

Language switch based on parameters and session state

I use this to set language session for navigation. Someone said that this switch is too cumbersome. Why? Is there an easier way?

$defaultLang = 'it';

if (!empty($_GET["lang"])) {
    switch (strtolower($_GET["lang"])) {
        case "en":
            
            $_SESSION['lang'] = 'gb';
            break;
        case "tr":
            
            $_SESSION['lang'] = 'tr';
            break;
        default:
            
            $_SESSION['lang'] = $defaultLang;
            break;
    }
}

if (empty($_SESSION["lang"])) {
        $_SESSION["lang"] = $defaultLang;
} 
Source Link
Ogum
  • 133
  • 2

Is this switch too cumbersome?

Someone said that this switch is too cumbersome.Why? Is there an easier way? I use this to set language session for navigation.

Thanks

$defaultLang = 'it';

if (!empty($_GET["lang"])) {
    switch (strtolower($_GET["lang"])) {
        case "en":
            
            $_SESSION['lang'] = 'gb';
            break;
        case "tr":
            
            $_SESSION['lang'] = 'tr';
            break;
        default:
            
            $_SESSION['lang'] = $defaultLang;
            break;
    }
}

if (empty($_SESSION["lang"])) {
        $_SESSION["lang"] = $defaultLang;
}