Identify language from a request/session parameter.
$languages: An array of valid language objects.
A valid language code on success, FALSE otherwise.
function language_from_session($languages) {
$param = config('language.negotiation')
->get('session.parameter');
// Request parameter: we need to update the session parameter only if we have
// an authenticated user.
if (isset($_GET[$param]) && isset($languages[$langcode = $_GET[$param]])) {
global $user;
if ($user->uid) {
$_SESSION[$param] = $langcode;
}
return $langcode;
}
// Session parameter.
if (isset($_SESSION[$param])) {
return $_SESSION[$param];
}
return FALSE;
}