Commit 966e804b authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Only cache user preference in current_language function (bug #800512)

Logged-in user language preferences were broken in commit 9ca6bb55

.
This change removes caching on the session and config languages, which
are quick to retrieve anyway, but leaves it in place for the user
language preference and locale setting.

Change-Id: Ib601f2227409bbbc63d269fe079915cc0e902fc2
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent d96c14ea
......@@ -484,7 +484,6 @@ function auth_setup () {
if (defined('PUBLIC') && !isset($_GET['login'])) {
if ($lang = param_alphanumext('lang', null)) {
$SESSION->set('lang', $lang);
current_language($lang);
}
return;
}
......
......@@ -1175,11 +1175,6 @@ class LiveUser extends User {
$this->set_account_preference('lang', $sessionlang);
}
// Set language for the current request
if (!empty($this->accountprefs['lang'])) {
current_language($this->accountprefs['lang']);
}
$this->reset_institutions();
$this->reset_grouproles();
$this->load_views();
......
......@@ -940,42 +940,29 @@ function print_object($mixed) {
* language to use, either for a given user
* or sitewide, or the default
*
* param @string $reset If passed, reset the current language to this
*
* @return string
*/
function current_language($reset=null) {
function current_language() {
global $USER, $CFG, $SESSION;
static $lang, $cfglang;
if (!isset($cfglang) && isset($CFG->lang) && !empty($CFG->lang) && is_null($reset)) {
// This is the first call to current_language after load_config, so ensure the
// language is reset.
$reset = $cfglang = $CFG->lang;
}
static $userlang, $lastlang;
if (!empty($reset)) {
$lang = $reset; // Set the language for this request
}
if (!empty($lang)) {
return $lang;
}
$loggedin = $USER instanceof User && $USER->is_logged_in();
if ($USER instanceof User) {
if (!isset($userlang) && $loggedin) {
$userlang = $USER->get_account_preference('lang');
if ($userlang !== null && $userlang != 'default') {
if (language_installed($userlang)) {
$lang = $userlang;
}
else {
if (!language_installed($userlang)) {
$USER->set_account_preference('lang', 'default');
$userlang = 'default';
}
}
}
if (empty($lang) && is_a($SESSION, 'Session')) {
if (!empty($userlang) && $userlang != 'default') {
$lang = $userlang;
}
else if (!$loggedin && is_a($SESSION, 'Session')) {
$sesslang = $SESSION->get('lang');
if (!empty($sesslang) && $sesslang != 'default') {
$lang = $sesslang;
......@@ -986,6 +973,10 @@ function current_language($reset=null) {
$lang = !empty($CFG->lang) ? $CFG->lang : 'en.utf8';
}
if ($lang == $lastlang) {
return $lang;
}
// Set locale. We are probably being called from get_string_location.
// $lang had better be non-empty, or it will call us again.
if ($args = split(',', get_string_location('locales', 'langconfig', array(), 'raw_langstring', $lang))) {
......@@ -993,7 +984,7 @@ function current_language($reset=null) {
call_user_func_array('setlocale', $args);
}
return $lang;
return $lastlang = $lang;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment