$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)) {
if (empty($config)) {
$config = $CFG;
- if (!$config->locale = get_field('config', 'value', 'name', 'locale')) {
- $config->locale = $CFG->lang;
- }
}
$sesskey = !empty($USER->id) ? $USER->sesskey : '';
/// 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'),
$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.';
'langcache' => 1,
'langmenu' => 1,
'langlist' => '',
- 'locale' => 'en',
+ 'locale' => '', // by default language pack locales should be used
'loginhttps' => false,
'loglifetime' => 0,
'longtimenosee' => 100,
// 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;
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;
}
}
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';
$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,
$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);
}
}
$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)) {
function print_header ($title='', $heading='', $navigation='', $focus='', $meta='',
$cache=true, $button=' ', $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')) {
}
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
$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) {
if(!empty($CFG->courselang)) {
unset($CFG->courselang);
}
- if(!empty($CFG->locale)) {
- unset($CFG->locale);
- }
$CFG->lang = $lang;
moodle_setlocale();
}