]> git.mjollnir.org Git - moodle.git/commitdiff
Bug #6176 - locale setting on config variables page not functioning correctly; merged...
authorskodak <skodak>
Sun, 30 Jul 2006 10:39:21 +0000 (10:39 +0000)
committerskodak <skodak>
Sun, 30 Jul 2006 10:39:21 +0000 (10:39 +0000)
admin/config.php
admin/configvars.php
lang/en_utf8/admin.php
lib/defaults.php
lib/moodlelib.php
lib/setup.php
lib/weblib.php
mod/chat/lib.php

index 959bf2b762456f379e5cd84d1d3fb46de22fb75c..9c396dd1a2c8891159e714c3502be83317f0c123 100644 (file)
                         $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 : '';
index 59087ccee880eebf257a5cd25d437033f5419740..9849dcc60f2372f28d20809209774d40dce555a5 100644 (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'),
index 53711a0dcd39c87d906856cc4587cacbf5887448..9d541e91672751fcf937a3a7009f4a63103d5fc8 100644 (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.';
index 771e9f4771b7ef5068d31ce5a33de01f9f60af3e..e9d982eca23f16d44fab66a570e10b582fb94efb 100644 (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,
index b27faf03754f1106bd8004eca65e044b2da3c6db..80bda95bdfef28cd359b46b523c2bedd23c3bf54 100644 (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);
     }
 }
index 2558bd1c8a523f02499ae244e9a5153b55fa9cf4..6036e4230410bfc3cc3d448a045098576a460432 100644 (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)) {
index 6b9e6314642e0dc9c44e0741dd0d48cf56d0c8e9..5b2c3ae16f6e85fc037a6ccacb6cbcb1f5100ce8 100644 (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) {
index c8d550b08926c289d6d00523ad0f3c5118eafe25..88d1b98c5f1b5c53dff1f79b2a92103cf92d7cdb 100644 (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();
 }