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