Commit 4ca0fcae authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Store locale in langconfig; set locale when setting the language (bug #597097)


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 174dd121
......@@ -44,7 +44,7 @@ $string['strfdaymonthyearshort'] = '%%d/%%m/%%Y';
$string['strftimew3cdatetime'] = '%%Y-%%m-%%dT%%T%%z';
$string['strftimew3cdate'] = '%%Y-%%m-%%d';
$string['thislanguage'] = 'English';
$string['locales'] = 'en_US.utf8,en_GB.utf8,en';
?>
......@@ -335,8 +335,7 @@ function get_raw_string($identifier, $section='mahara') {
// For a raw string we don't want to format any arguments using
// sprintf, so the replace function passed to get_string_location
// should just return the first argument and ignore the second.
return get_string_location($identifier, $section, array(),
create_function('$string, $args','return $string;'));
return get_string_location($identifier, $section, array(), 'raw_langstring');
}
......@@ -929,26 +928,36 @@ function current_language() {
}
if ($USER instanceof User) {
$lang = $USER->get_account_preference('lang');
if ($lang !== null && $lang != 'default') {
if (language_installed($lang)) {
return $lang;
$userlang = $USER->get_account_preference('lang');
if ($userlang !== null && $userlang != 'default') {
if (language_installed($userlang)) {
$lang = $userlang;
}
else {
$USER->set_account_preference('lang', 'default');
}
}
}
if (is_a($SESSION, 'Session')) {
$lang = $SESSION->get('lang');
if (!empty($lang) && $lang != 'default') {
return $lang;
if (empty($lang) && is_a($SESSION, 'Session')) {
$sesslang = $SESSION->get('lang');
if (!empty($sesslang) && $sesslang != 'default') {
$lang = $sesslang;
}
}
if (!empty($CFG->lang)) {
return $lang = $CFG->lang;
if (empty($lang)) {
$lang = !empty($CFG->lang) ? $CFG->lang : 'en.utf8';
}
return $lang = 'en.utf8';
// 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))) {
array_unshift($args, LC_ALL);
call_user_func_array('setlocale', $args);
}
return $lang;
}
/**
......@@ -962,6 +971,10 @@ function format_langstring($string,$args) {
return call_user_func_array('sprintf',array_merge(array($string),$args));
}
function raw_langstring($string) {
return $string;
}
/**
* Helper function to figure out whether an array is an array or a hash
* @param array $array array to check
......
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