Bug #6176 - locale setting on config variables page not functioning correctly; merged from MOODLE_16_STABLE

This commit is contained in:
skodak 2006-07-30 10:39:21 +00:00
parent 8ee8f34bff
commit be933850a7
8 changed files with 52 additions and 34 deletions

View File

@ -46,7 +46,10 @@
$value = implode(',',$value);
}
}
unset($conf);
if ($name == "locale") {
$value = trim($value);
}
$conf = new object();
$conf->name = $name;
$conf->value = $value;
if ($current = get_record('config', 'name', $name)) {
@ -74,9 +77,6 @@
if (empty($config)) {
$config = $CFG;
if (!$config->locale = get_field('config', 'value', 'name', 'locale')) {
$config->locale = $CFG->lang;
}
}
$sesskey = !empty($USER->id) ? $USER->sesskey : '';

View File

@ -312,10 +312,10 @@ class configvarrss extends configvar {
/// language menu
$interface['langcache'] = new configvar ( get_string('configlangcache', 'admin'),
choose_from_menu($noyesoptions, 'langcache', $config->langcache, '', '', '', true) );
/// locale
$interface['locale'] = new configvar ( get_string('configlocale', 'admin'),
'<input name="locale" type="text" size="10" value="'.s($config->locale).'" alt="locale" />' );
'<input name="locale" type="text" size="15" value="'.s($config->locale).'" alt="locale" />' );
/// docroot
$interface['docroot'] = new configvar ( get_string('configdocroot', 'admin'),

View File

@ -70,7 +70,7 @@ $string['configlangcache'] = 'Cache the language menu. Saves a lot of memory and
$string['configlangdir'] = 'Most languages are printed left-to-right, but some, like Arabic and Hebrew, are printed right-to-left.';
$string['configlanglist'] = 'Leave this blank to allow users to choose from any language you have in this installation of Moodle. However, you can shorten the language menu by entering a comma-separated list of language codes that you want. For example: en,es_es,fr,it';
$string['configlangmenu'] = 'Choose whether or not you want to display the general-purpose language menu on the home page, login page etc. This does not affect the user\'s ability to set the preferred language in their own profile.';
$string['configlocale'] = 'Choose a sitewide locale - this will affect the format and language of dates. You need to have this locale data installed on your operating system. (eg en_US or es_ES). If you don\'t know what to choose leave it blank.';
$string['configlocale'] = 'Choose a sitewide locale - this will override the format and language of dates for all language packs (though names of days in calendar are not affected). You need to have this locale data installed on your operating system (eg for linux en_US.UTF-8 or es_ES.UTF-8). In most cases this field should be left blank.';
$string['configloginhttps'] = 'Turning this on will make Moodle use a secure https connection just for the login page (providing a secure login), and then afterwards revert back to the normal http URL for general speed. CAUTION: this setting REQUIRES https to be specifically enabled on the web server - if it is not then YOU COULD LOCK YOURSELF OUT OF YOUR SITE.';
$string['configloglifetime'] = 'This specifies the length of time you want to keep logs about user activity. Logs that are older than this age are automatically deleted. It is best to keep logs as long as possible, in case you need them, but if you have a very busy server and are experiencing performance problems, then you may want to lower the log lifetime.';
$string['configlongtimenosee'] = 'If students haven\'t logged in for a very long time, then they are automatically unsubscribed from courses. This parameter specifies that time limit.';

View File

@ -60,7 +60,7 @@
'langcache' => 1,
'langmenu' => 1,
'langlist' => '',
'locale' => 'en',
'locale' => '', // by default language pack locales should be used
'loginhttps' => false,
'loglifetime' => 0,
'longtimenosee' => 100,

View File

@ -1507,12 +1507,17 @@ function require_login($courseid=0, $autologinguest=true, $cm=null) {
// Redefine global $COURSE if we can
global $course; // We use the global hack once here so it doesn't need to be used again
if (is_object($course)) {
if (is_object($course) and !empty($course->id) and ($courseid == 0 or $course->id == $courseid)) {
$COURSE = clone($course);
} else if ($courseid) {
$COURSE = get_record('course', 'id', $courseid);
}
if (!empty($COURSE->lang)) {
$CFG->courselang = $COURSE->lang;
moodle_setlocale();
}
// First check that the user is logged in to the site.
if (! (isset($USER->loggedin) and $USER->confirmed and ($USER->site == $CFG->wwwroot)) ) { // They're not
$SESSION->wantsurl = $FULLME;
@ -4698,9 +4703,11 @@ function get_string($identifier, $module='', $a=NULL) {
global $CFG;
global $course; /// Not a nice hack, but quick
global $course, $COURSE;
if (empty($CFG->courselang)) {
if (is_object($course) and isset($course->lang)) {
if (!empty($COURSE->lang)) {
$CFG->courselang = $COURSE->lang;
} else if (!empty($course->lang)) { // ugly backwards compatibility hack
$CFG->courselang = $course->lang;
}
}
@ -5918,6 +5925,13 @@ function moodle_setlocale($locale='') {
global $SESSION, $USER, $CFG;
static $currentlocale; // last locale caching
if (!isset($currentlocale)) {
$currentlocale = '';
}
$oldlocale = $currentlocale;
/// Fetch the correct locale based on ostype
if(!empty($CFG->unicodedb) && $CFG->ostype == 'WINDOWS') {
$stringtofetch = 'localewin';
@ -5925,19 +5939,18 @@ function moodle_setlocale($locale='') {
$stringtofetch = 'locale';
}
if ($locale) {
$CFG->locale = $locale;
} else if (!empty($CFG->courselang) and ($CFG->courselang != $CFG->lang) ) {
$CFG->locale = get_string($stringtofetch);
} else if (!empty($SESSION->lang) and ($SESSION->lang != $CFG->lang) ) {
$CFG->locale = get_string($stringtofetch);
} else if (!empty($USER->lang) and ($USER->lang != $CFG->lang) ) {
$CFG->locale = get_string($stringtofetch);
} else if (empty($CFG->locale)) {
$CFG->locale = get_string($stringtofetch);
if (!get_field('config', 'value', 'name', 'locale')) { // Make SURE there isn't one already
set_config('locale', $CFG->locale); // Cache it to save lookups in future
}
/// the priority is the same as in get_string() - parameter, config, course, session, user, global language
if (!empty($locale)) {
$currentlocale = $locale;
} else if (!empty($CFG->locale)) { // override locale for all language packs
$currentlocale = $CFG->locale;
} else {
$currentlocale = get_string($stringtofetch);
}
/// do nothing if locale already set up
if ($oldlocale == $currentlocale) {
return;
}
/// Due to some strange BUG we cannot set the LC_TIME directly, so we fetch current values,
@ -5952,14 +5965,14 @@ function moodle_setlocale($locale='') {
$messages= setlocale (LC_MESSAGES, 0);
}
/// Set locale to all
setlocale (LC_ALL, $CFG->locale);
setlocale (LC_ALL, $currentlocale);
/// Set old values
setlocale (LC_MONETARY, $monetary);
setlocale (LC_NUMERIC, $numeric);
if ($CFG->ostype != 'WINDOWS') {
setlocale (LC_MESSAGES, $messages);
}
if ($CFG->locale == 'tr_TR' or $CFG->locale == 'tr_TR.UTF-8') { // To workaround a well-known PHP bug with Turkish
if ($currentlocale == 'tr_TR' or $currentlocale == 'tr_TR.UTF-8') { // To workaround a well-known PHP problem with Turkish letter Ii
setlocale (LC_CTYPE, $ctype);
}
}

View File

@ -508,6 +508,7 @@ $CFG->os = PHP_OS;
$CFG->lang = !empty($CFG->unicodedb) ? 'en_utf8' : 'en';
}
// set default locale - might be changed again later in require_login()
moodle_setlocale();
if (!empty($CFG->opentogoogle)) {

View File

@ -1882,7 +1882,7 @@ function highlightfast($needle, $haystack) {
function print_header ($title='', $heading='', $navigation='', $focus='', $meta='',
$cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='') {
global $USER, $CFG, $THEME, $SESSION, $ME, $SITE, $COURSE, $HTTPSPAGEREQUIRED;
global $USER, $CFG, $THEME, $SESSION, $ME, $SITE, $HTTPSPAGEREQUIRED;
/// This makes sure that the header is never repeated twice on a page
if (defined('HEADER_PRINTED')) {
@ -1893,15 +1893,25 @@ function print_header ($title='', $heading='', $navigation='', $focus='', $meta=
}
define('HEADER_PRINTED', 'true');
/// Set up course-based lang and theme if any
global $course, $COURSE;
if (!empty($COURSE->lang)) {
$CFG->courselang = $COURSE->lang;
moodle_setlocale();
} else if (!empty($course->lang)) { // ugly backwards compatibility hack
$CFG->courselang = $course->lang;
moodle_setlocale();
}
if (!empty($COURSE->theme)) {
if (!empty($CFG->allowcoursethemes)) {
$CFG->coursetheme = $COURSE->theme;
theme_setup();
}
} else if (!empty($course->theme)) { // ugly backwards compatibility hack
if (!empty($CFG->allowcoursethemes)) {
$CFG->coursetheme = $course->theme;
theme_setup();
}
}
/// We have to change some URLs in styles if we are in a $HTTPSPAGEREQUIRED page
@ -1977,9 +1987,6 @@ function print_header ($title='', $heading='', $navigation='', $focus='', $meta=
$encoding = current_charset();
if (!empty($CFG->courselang)) {
moodle_setlocale();
}
$meta = '<meta http-equiv="content-type" content="text/html; charset='. $encoding .'" />'. "\n". $meta ."\n";
if (!$usexml) {

View File

@ -321,9 +321,6 @@ function chat_force_language($lang) {
if(!empty($CFG->courselang)) {
unset($CFG->courselang);
}
if(!empty($CFG->locale)) {
unset($CFG->locale);
}
$CFG->lang = $lang;
moodle_setlocale();
}