Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some fixes for locales in a very multilibgual site (eg moodle.org)

  • Loading branch information...
commit 20761eb71d603cb85d956fcba19630fe75ba50e8 1 parent 734bdb6
moodler authored
Showing with 51 additions and 17 deletions.
  1. +24 −0 lib/moodlelib.php
  2. +1 −13 lib/setup.php
  3. +26 −4 lib/weblib.php
View
24 lib/moodlelib.php
@@ -2300,6 +2300,30 @@ function moodle_needs_upgrading() {
/// MISCELLANEOUS ////////////////////////////////////////////////////////////////////
+function moodle_setlocale($locale='') {
+
+ global $SESSION, $USER, $CFG;
+
+ if ($locale) {
+ $CFG->locale = $locale;
+ } else if (!empty($CFG->courselang) and ($CFG->courselang != $CFG->lang) ) {
+ $CFG->locale = get_string('locale');
+ } else if (!empty($SESSION->lang) and ($SESSION->lang != $CFG->lang) ) {
+ $CFG->locale = get_string('locale');
+ } else if (!empty($USER->lang) and ($USER->lang != $CFG->lang) ) {
+ $CFG->locale = get_string('locale');
+ } else if (empty($CFG->locale)) {
+ $CFG->locale = get_string('locale');
+ set_config('locale', $CFG->locale); // cache it to save lookups in future
+ }
+ setlocale (LC_TIME, $CFG->locale);
+ setlocale (LC_COLLATE, $CFG->locale);
+
+ if ($CFG->locale != 'tr_TR') { // To workaround a well-known PHP bug with Turkish
+ setlocale (LC_CTYPE, $CFG->locale);
+ }
+}
+
function moodle_strtolower ($string, $encoding='') {
/// Converts string to lowercase using most compatible function available
if (function_exists('mb_strtolower')) {
View
14 lib/setup.php
@@ -224,20 +224,8 @@ class object {};
if (empty($CFG->lang)) {
$CFG->lang = "en";
}
- if (!empty($SESSION->lang) and ($SESSION->lang != $CFG->lang) ) {
- $CFG->locale = get_string('locale');
- } else if (!empty($USER->lang) and ($USER->lang != $CFG->lang) ) {
- $CFG->locale = get_string('locale');
- } else if (empty($CFG->locale)) {
- $CFG->locale = get_string('locale');
- set_config('locale', $CFG->locale); // cache it to save lookups in future
- }
- setlocale (LC_TIME, $CFG->locale);
- setlocale (LC_COLLATE, $CFG->locale);
- if ($CFG->locale != 'tr_TR') { // To workaround a well-known PHP bug with Turkish
- setlocale (LC_CTYPE, $CFG->locale);
- }
+ moodle_setlocale();
if (!empty($CFG->opentogoogle)) {
if (empty($_SESSION['USER'])) {
View
30 lib/weblib.php
@@ -965,11 +965,15 @@ function print_header ($title="", $heading="", $navigation="", $focus="", $meta=
if (!empty($CFG->unicode)) {
$encoding = "utf-8";
- } else if (!empty($SESSION->encoding) and empty($CFG->courselang)) {
- $encoding = $SESSION->encoding;
- } else {
+ } else if (!empty($CFG->courselang)) {
$encoding = get_string("thischarset");
- $SESSION->encoding = $encoding;
+ moodle_setlocale();
+ } else {
+ if (!empty($SESSION->encoding)) {
+ $encoding = $SESSION->encoding;
+ } else {
+ $SESSION->encoding = $encoding = get_string("thischarset");
+ }
}
$meta = "<meta http-equiv=\"content-type\" content=\"text/html; charset=$encoding\" />\n$meta\n";
@@ -1930,6 +1934,24 @@ function print_time_selector($hour, $minute, $currenttime=0, $step=5) {
choose_from_menu($minutes, $minute, $currentdate['minutes'], "");
}
+function print_timer_selector($timelimit = 0, $unit = "") {
+/// Prints time limit value selector
+
+ global $CFG;
+
+ if ($unit) {
+ $unit = ' '.$unit;
+ }
+
+ // Max timelimit is sessiontimeout - 10 minutes.
+ $maxvalue = ($CFG->sessiontimeout / 60) - 10;
+
+ for ($i=1; $i<=$maxvalue; $i++) {
+ $minutes[$i] = $i.$unit;
+ }
+ choose_from_menu($minutes, "timelimit", $timelimit, get_string("none"));
+}
+
function print_grade_menu($courseid, $name, $current, $includenograde=true) {
/// Prints a grade menu (as part of an existing form) with help
/// Showing all possible numerical grades and scales
Please sign in to comment.
Something went wrong with that request. Please try again.