mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-43497 Language: Allow course language to be overridden
This commit is contained in:
parent
76e4de31cc
commit
c484af5aa6
7 changed files with 70 additions and 63 deletions
|
@ -399,7 +399,7 @@ class enrol_flatfile_plugin extends enrol_plugin {
|
||||||
* @param bool $buffer_if_future
|
* @param bool $buffer_if_future
|
||||||
*/
|
*/
|
||||||
protected function process_records(progress_trace $trace, $action, $roleid, $user, $course, $timestart, $timeend, $buffer_if_future = true) {
|
protected function process_records(progress_trace $trace, $action, $roleid, $user, $course, $timestart, $timeend, $buffer_if_future = true) {
|
||||||
global $CFG, $DB, $SESSION;
|
global $CFG, $DB;
|
||||||
|
|
||||||
// Check if timestart is for future processing.
|
// Check if timestart is for future processing.
|
||||||
if ($timestart > time() and $buffer_if_future) {
|
if ($timestart > time() and $buffer_if_future) {
|
||||||
|
@ -448,12 +448,7 @@ class enrol_flatfile_plugin extends enrol_plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($notify and $this->get_config('mailstudents')) {
|
if ($notify and $this->get_config('mailstudents')) {
|
||||||
// Some nasty hackery to get strings and dates localised for target user.
|
$oldforcelang = force_current_language($user->lang);
|
||||||
$sessionlang = isset($SESSION->lang) ? $SESSION->lang : null;
|
|
||||||
if (get_string_manager()->translation_exists($user->lang, false)) {
|
|
||||||
$SESSION->lang = $user->lang;
|
|
||||||
moodle_setlocale();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send welcome notification to enrolled users.
|
// Send welcome notification to enrolled users.
|
||||||
$a = new stdClass();
|
$a = new stdClass();
|
||||||
|
@ -478,22 +473,14 @@ class enrol_flatfile_plugin extends enrol_plugin {
|
||||||
$trace->output("Failed to notify enrolled user", 1);
|
$trace->output("Failed to notify enrolled user", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($SESSION->lang !== $sessionlang) {
|
force_current_language($oldforcelang);
|
||||||
$SESSION->lang = $sessionlang;
|
|
||||||
moodle_setlocale();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($notify and $this->get_config('mailteachers', 0)) {
|
if ($notify and $this->get_config('mailteachers', 0)) {
|
||||||
// Notify person responsible for enrolments.
|
// Notify person responsible for enrolments.
|
||||||
$enroller = $this->get_enroller($course->id);
|
$enroller = $this->get_enroller($course->id);
|
||||||
|
|
||||||
// Some nasty hackery to get strings and dates localised for target user.
|
$oldforcelang = force_current_language($enroller->lang);
|
||||||
$sessionlang = isset($SESSION->lang) ? $SESSION->lang : null;
|
|
||||||
if (get_string_manager()->translation_exists($enroller->lang, false)) {
|
|
||||||
$SESSION->lang = $enroller->lang;
|
|
||||||
moodle_setlocale();
|
|
||||||
}
|
|
||||||
|
|
||||||
$a = new stdClass();
|
$a = new stdClass();
|
||||||
$a->course = format_string($course->fullname, true, array('context' => $context));
|
$a->course = format_string($course->fullname, true, array('context' => $context));
|
||||||
|
@ -517,10 +504,7 @@ class enrol_flatfile_plugin extends enrol_plugin {
|
||||||
$trace->output("Failed to notify enroller {$eventdata->userto->id}", 1);
|
$trace->output("Failed to notify enroller {$eventdata->userto->id}", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($SESSION->lang !== $sessionlang) {
|
force_current_language($oldforcelang);
|
||||||
$SESSION->lang = $sessionlang;
|
|
||||||
moodle_setlocale();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -677,7 +677,7 @@ function login_attempt_failed($user) {
|
||||||
* @param stdClass $user
|
* @param stdClass $user
|
||||||
*/
|
*/
|
||||||
function login_lock_account($user) {
|
function login_lock_account($user) {
|
||||||
global $CFG, $SESSION;
|
global $CFG;
|
||||||
|
|
||||||
if ($user->mnethostid != $CFG->mnet_localhost_id) {
|
if ($user->mnethostid != $CFG->mnet_localhost_id) {
|
||||||
return;
|
return;
|
||||||
|
@ -699,12 +699,7 @@ function login_lock_account($user) {
|
||||||
$secret = random_string(15);
|
$secret = random_string(15);
|
||||||
set_user_preference('login_lockout_secret', $secret, $user);
|
set_user_preference('login_lockout_secret', $secret, $user);
|
||||||
|
|
||||||
// Some nasty hackery to get strings and dates localised for target user.
|
$oldforcelang = force_current_language($user->lang);
|
||||||
$sessionlang = isset($SESSION->lang) ? $SESSION->lang : null;
|
|
||||||
if (get_string_manager()->translation_exists($user->lang, false)) {
|
|
||||||
$SESSION->lang = $user->lang;
|
|
||||||
moodle_setlocale();
|
|
||||||
}
|
|
||||||
|
|
||||||
$site = get_site();
|
$site = get_site();
|
||||||
$supportuser = core_user::get_support_user();
|
$supportuser = core_user::get_support_user();
|
||||||
|
@ -725,10 +720,7 @@ function login_lock_account($user) {
|
||||||
email_to_user($user, $supportuser, $subject, $message);
|
email_to_user($user, $supportuser, $subject, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($SESSION->lang !== $sessionlang) {
|
force_current_language($oldforcelang);
|
||||||
$SESSION->lang = $sessionlang;
|
|
||||||
moodle_setlocale();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2013,5 +2013,12 @@ $capabilities = array(
|
||||||
'teacher' => CAP_ALLOW,
|
'teacher' => CAP_ALLOW,
|
||||||
'editingteacher' => CAP_ALLOW,
|
'editingteacher' => CAP_ALLOW,
|
||||||
)
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
'moodle/site:forcelanguage' => array(
|
||||||
|
'captype' => 'read',
|
||||||
|
'contextlevel' => CONTEXT_SYSTEM,
|
||||||
|
'archetypes' => array(
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -2146,16 +2146,11 @@ abstract class enrol_plugin {
|
||||||
* @param progress_trace $trace
|
* @param progress_trace $trace
|
||||||
*/
|
*/
|
||||||
protected function notify_expiry_enrolled($user, $ue, progress_trace $trace) {
|
protected function notify_expiry_enrolled($user, $ue, progress_trace $trace) {
|
||||||
global $CFG, $SESSION;
|
global $CFG;
|
||||||
|
|
||||||
$name = $this->get_name();
|
$name = $this->get_name();
|
||||||
|
|
||||||
// Some nasty hackery to get strings and dates localised for target user.
|
$oldforcelang = force_current_language($user->lang);
|
||||||
$sessionlang = isset($SESSION->lang) ? $SESSION->lang : null;
|
|
||||||
if (get_string_manager()->translation_exists($user->lang, false)) {
|
|
||||||
$SESSION->lang = $user->lang;
|
|
||||||
moodle_setlocale();
|
|
||||||
}
|
|
||||||
|
|
||||||
$enroller = $this->get_enroller($ue->enrolid);
|
$enroller = $this->get_enroller($ue->enrolid);
|
||||||
$context = context_course::instance($ue->courseid);
|
$context = context_course::instance($ue->courseid);
|
||||||
|
@ -2189,10 +2184,7 @@ abstract class enrol_plugin {
|
||||||
$trace->output("error notifying user $ue->userid that enrolment in course $ue->courseid expires on ".userdate($ue->timeend, '', $CFG->timezone), 1);
|
$trace->output("error notifying user $ue->userid that enrolment in course $ue->courseid expires on ".userdate($ue->timeend, '', $CFG->timezone), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($SESSION->lang !== $sessionlang) {
|
force_current_language($oldforcelang);
|
||||||
$SESSION->lang = $sessionlang;
|
|
||||||
moodle_setlocale();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2207,7 +2199,7 @@ abstract class enrol_plugin {
|
||||||
* @param progress_trace $trace
|
* @param progress_trace $trace
|
||||||
*/
|
*/
|
||||||
protected function notify_expiry_enroller($eid, $users, progress_trace $trace) {
|
protected function notify_expiry_enroller($eid, $users, progress_trace $trace) {
|
||||||
global $DB, $SESSION;
|
global $DB;
|
||||||
|
|
||||||
$name = $this->get_name();
|
$name = $this->get_name();
|
||||||
|
|
||||||
|
@ -2218,12 +2210,7 @@ abstract class enrol_plugin {
|
||||||
$enroller = $this->get_enroller($instance->id);
|
$enroller = $this->get_enroller($instance->id);
|
||||||
$admin = get_admin();
|
$admin = get_admin();
|
||||||
|
|
||||||
// Some nasty hackery to get strings and dates localised for target user.
|
$oldforcelang = force_current_language($enroller->lang);
|
||||||
$sessionlang = isset($SESSION->lang) ? $SESSION->lang : null;
|
|
||||||
if (get_string_manager()->translation_exists($enroller->lang, false)) {
|
|
||||||
$SESSION->lang = $enroller->lang;
|
|
||||||
moodle_setlocale();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($users as $key=>$info) {
|
foreach($users as $key=>$info) {
|
||||||
$users[$key] = '* '.$info['fullname'].' - '.userdate($info['timeend'], '', $enroller->timezone);
|
$users[$key] = '* '.$info['fullname'].' - '.userdate($info['timeend'], '', $enroller->timezone);
|
||||||
|
@ -2258,10 +2245,7 @@ abstract class enrol_plugin {
|
||||||
$trace->output("error notifying user $enroller->id about all expiring $name enrolments in course $instance->courseid", 1);
|
$trace->output("error notifying user $enroller->id about all expiring $name enrolments in course $instance->courseid", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($SESSION->lang !== $sessionlang) {
|
force_current_language($oldforcelang);
|
||||||
$SESSION->lang = $sessionlang;
|
|
||||||
moodle_setlocale();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4856,6 +4856,7 @@ function set_login_session_preferences() {
|
||||||
$SESSION->justloggedin = true;
|
$SESSION->justloggedin = true;
|
||||||
|
|
||||||
unset($SESSION->lang);
|
unset($SESSION->lang);
|
||||||
|
unset($SESSION->forcelang);
|
||||||
unset($SESSION->load_navigation_admin);
|
unset($SESSION->load_navigation_admin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6623,7 +6624,14 @@ function clean_filename($string) {
|
||||||
function current_language() {
|
function current_language() {
|
||||||
global $CFG, $USER, $SESSION, $COURSE;
|
global $CFG, $USER, $SESSION, $COURSE;
|
||||||
|
|
||||||
if (!empty($COURSE->id) and $COURSE->id != SITEID and !empty($COURSE->lang)) {
|
if (!empty($SESSION->forcelang)) {
|
||||||
|
// Allows overriding course-forced language (useful for admins to check
|
||||||
|
// issues in courses whose language they don't understand).
|
||||||
|
// Also used by some code to temporarily get language-related information in a
|
||||||
|
// specific language (see force_current_language()).
|
||||||
|
$return = $SESSION->forcelang;
|
||||||
|
|
||||||
|
} else if (!empty($COURSE->id) and $COURSE->id != SITEID and !empty($COURSE->lang)) {
|
||||||
// Course language can override all other settings for this page.
|
// Course language can override all other settings for this page.
|
||||||
$return = $COURSE->lang;
|
$return = $COURSE->lang;
|
||||||
|
|
||||||
|
@ -6655,14 +6663,10 @@ function current_language() {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function get_parent_language($lang=null) {
|
function get_parent_language($lang=null) {
|
||||||
global $COURSE, $SESSION;
|
|
||||||
|
|
||||||
// Let's hack around the current language.
|
// Let's hack around the current language.
|
||||||
if (!empty($lang)) {
|
if (!empty($lang)) {
|
||||||
$oldcourselang = empty($COURSE->lang) ? '' : $COURSE->lang;
|
$oldforcelang = force_current_language($lang);
|
||||||
$oldsessionlang = empty($SESSION->lang) ? '' : $SESSION->lang;
|
|
||||||
$COURSE->lang = '';
|
|
||||||
$SESSION->lang = $lang;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$parentlang = get_string('parentlanguage', 'langconfig');
|
$parentlang = get_string('parentlanguage', 'langconfig');
|
||||||
|
@ -6672,13 +6676,34 @@ function get_parent_language($lang=null) {
|
||||||
|
|
||||||
// Let's hack around the current language.
|
// Let's hack around the current language.
|
||||||
if (!empty($lang)) {
|
if (!empty($lang)) {
|
||||||
$COURSE->lang = $oldcourselang;
|
force_current_language($oldforcelang);
|
||||||
$SESSION->lang = $oldsessionlang;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $parentlang;
|
return $parentlang;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force the current language to get strings and dates localised in the given language.
|
||||||
|
*
|
||||||
|
* After calling this function, all strings will be provided in the given language
|
||||||
|
* until this function is called again, or equivalent code is run.
|
||||||
|
*
|
||||||
|
* @param string $language
|
||||||
|
* @return string previous $SESSION->forcelang value
|
||||||
|
*/
|
||||||
|
function force_current_language($language) {
|
||||||
|
global $SESSION;
|
||||||
|
$sessionforcelang = isset($SESSION->forcelang) ? $SESSION->forcelang : '';
|
||||||
|
if ($language !== $sessionforcelang) {
|
||||||
|
// Seting forcelang to null or an empty string disables it's effect.
|
||||||
|
if (empty($language) || get_string_manager()->translation_exists($language, false)) {
|
||||||
|
$SESSION->forcelang = $language;
|
||||||
|
moodle_setlocale();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $sessionforcelang;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns current string_manager instance.
|
* Returns current string_manager instance.
|
||||||
*
|
*
|
||||||
|
|
|
@ -820,6 +820,21 @@ if (isset($_GET['lang']) and ($lang = optional_param('lang', '', PARAM_SAFEDIR))
|
||||||
}
|
}
|
||||||
unset($lang);
|
unset($lang);
|
||||||
|
|
||||||
|
// PARAM_SAFEDIR used instead of PARAM_LANG because using PARAM_LANG results
|
||||||
|
// in an empty string being returned when a non-existant language is specified,
|
||||||
|
// which would make it necessary to log out to undo the forcelang setting.
|
||||||
|
// With PARAM_SAFEDIR, it's possible to specify ?forcelang=none to drop the forcelang effect.
|
||||||
|
if ($forcelang = optional_param('forcelang', '', PARAM_SAFEDIR)) {
|
||||||
|
if (isloggedin()
|
||||||
|
&& get_string_manager()->translation_exists($forcelang, false)
|
||||||
|
&& has_capability('moodle/site:forcelanguage', context_system::instance())) {
|
||||||
|
$SESSION->forcelang = $forcelang;
|
||||||
|
} else if (isset($SESSION->forcelang)) {
|
||||||
|
unset($SESSION->forcelang);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($forcelang);
|
||||||
|
|
||||||
setup_lang_from_browser();
|
setup_lang_from_browser();
|
||||||
|
|
||||||
if (empty($CFG->lang)) {
|
if (empty($CFG->lang)) {
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$version = 2014022800.00; // YYYYMMDD = weekly release date of this DEV branch.
|
$version = 2014022800.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||||
// RR = release increments - 00 in DEV branches.
|
// RR = release increments - 00 in DEV branches.
|
||||||
// .XX = incremental changes.
|
// .XX = incremental changes.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue