If your code is working then there’s no need to change it. The suggestions I made were just personal style. People write code very differently, and you should do whatever works well for you.
You could assign a $language (or $_SESSION[’language’]) var at the beginning like so:
$language=(isset($_GET['lang'])) ? $_GET['lang'] : (isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'eng');
Some people hate ternary operators - and especially nested ones like this - because they’re more difficult to read and debug. This is just the equivalent of if..elseif...else, but it’s a lot shorter. If you wanted to do something else other than assign the value of $language in one or more of these conditions (for example, set the cookie if there’s a GET value), then if statements would definitely be better.
A switch statement might make your $output generation more readable, and it’s generally better to write MODx snippets to return one output at the end rather than echoing throughout. I’m assuming that you’re writing a snippet here, anyway. In order to have a single exit point and return one output var, I’d probably do something like this:
$output='';
...
other code in here... setting the language var, cookies, whatever...
...
switch ($language){
case 'ker':
$output=$outputKer;
break;
case 'eng':
$output=$outputEng;
break;
default:
$output=$outputEng;
}
return $output;
You could set link placeholders or whatever else you need within this also. As you can see, the English case may be redundant if that’s your default, so you could just eliminate that. Using a switch statement is more of a preference than a best practice, but you should definitely return just one value from each snippet rather than echoing throughout them.