mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-43497 Language: Allow course language to be overridden
This commit is contained in:
parent
76e4de31cc
commit
c484af5aa6
@ -399,7 +399,7 @@ class enrol_flatfile_plugin extends enrol_plugin {
|
||||
* @param bool $buffer_if_future
|
||||
*/
|
||||
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.
|
||||
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')) {
|
||||
// Some nasty hackery to get strings and dates localised for target user.
|
||||
$sessionlang = isset($SESSION->lang) ? $SESSION->lang : null;
|
||||
if (get_string_manager()->translation_exists($user->lang, false)) {
|
||||
$SESSION->lang = $user->lang;
|
||||
moodle_setlocale();
|
||||
}
|
||||
$oldforcelang = force_current_language($user->lang);
|
||||
|
||||
// Send welcome notification to enrolled users.
|
||||
$a = new stdClass();
|
||||
@ -478,22 +473,14 @@ class enrol_flatfile_plugin extends enrol_plugin {
|
||||
$trace->output("Failed to notify enrolled user", 1);
|
||||
}
|
||||
|
||||
if ($SESSION->lang !== $sessionlang) {
|
||||
$SESSION->lang = $sessionlang;
|
||||
moodle_setlocale();
|
||||
}
|
||||
force_current_language($oldforcelang);
|
||||
}
|
||||
|
||||
if ($notify and $this->get_config('mailteachers', 0)) {
|
||||
// Notify person responsible for enrolments.
|
||||
$enroller = $this->get_enroller($course->id);
|
||||
|
||||
// Some nasty hackery to get strings and dates localised for target user.
|
||||
$sessionlang = isset($SESSION->lang) ? $SESSION->lang : null;
|
||||
if (get_string_manager()->translation_exists($enroller->lang, false)) {
|
||||
$SESSION->lang = $enroller->lang;
|
||||
moodle_setlocale();
|
||||
}
|
||||
$oldforcelang = force_current_language($enroller->lang);
|
||||
|
||||
$a = new stdClass();
|
||||
$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);
|
||||
}
|
||||
|
||||
if ($SESSION->lang !== $sessionlang) {
|
||||
$SESSION->lang = $sessionlang;
|
||||
moodle_setlocale();
|
||||
}
|
||||
force_current_language($oldforcelang);
|
||||
}
|
||||
return;
|
||||
|
||||
|
@ -677,7 +677,7 @@ function login_attempt_failed($user) {
|
||||
* @param stdClass $user
|
||||
*/
|
||||
function login_lock_account($user) {
|
||||
global $CFG, $SESSION;
|
||||
global $CFG;
|
||||
|
||||
if ($user->mnethostid != $CFG->mnet_localhost_id) {
|
||||
return;
|
||||
@ -699,12 +699,7 @@ function login_lock_account($user) {
|
||||
$secret = random_string(15);
|
||||
set_user_preference('login_lockout_secret', $secret, $user);
|
||||
|
||||
// Some nasty hackery to get strings and dates localised for target user.
|
||||
$sessionlang = isset($SESSION->lang) ? $SESSION->lang : null;
|
||||
if (get_string_manager()->translation_exists($user->lang, false)) {
|
||||
$SESSION->lang = $user->lang;
|
||||
moodle_setlocale();
|
||||
}
|
||||
$oldforcelang = force_current_language($user->lang);
|
||||
|
||||
$site = get_site();
|
||||
$supportuser = core_user::get_support_user();
|
||||
@ -725,10 +720,7 @@ function login_lock_account($user) {
|
||||
email_to_user($user, $supportuser, $subject, $message);
|
||||
}
|
||||
|
||||
if ($SESSION->lang !== $sessionlang) {
|
||||
$SESSION->lang = $sessionlang;
|
||||
moodle_setlocale();
|
||||
}
|
||||
force_current_language($oldforcelang);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2013,5 +2013,12 @@ $capabilities = array(
|
||||
'teacher' => 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
|
||||
*/
|
||||
protected function notify_expiry_enrolled($user, $ue, progress_trace $trace) {
|
||||
global $CFG, $SESSION;
|
||||
global $CFG;
|
||||
|
||||
$name = $this->get_name();
|
||||
|
||||
// Some nasty hackery to get strings and dates localised for target user.
|
||||
$sessionlang = isset($SESSION->lang) ? $SESSION->lang : null;
|
||||
if (get_string_manager()->translation_exists($user->lang, false)) {
|
||||
$SESSION->lang = $user->lang;
|
||||
moodle_setlocale();
|
||||
}
|
||||
$oldforcelang = force_current_language($user->lang);
|
||||
|
||||
$enroller = $this->get_enroller($ue->enrolid);
|
||||
$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);
|
||||
}
|
||||
|
||||
if ($SESSION->lang !== $sessionlang) {
|
||||
$SESSION->lang = $sessionlang;
|
||||
moodle_setlocale();
|
||||
}
|
||||
force_current_language($oldforcelang);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2207,7 +2199,7 @@ abstract class enrol_plugin {
|
||||
* @param progress_trace $trace
|
||||
*/
|
||||
protected function notify_expiry_enroller($eid, $users, progress_trace $trace) {
|
||||
global $DB, $SESSION;
|
||||
global $DB;
|
||||
|
||||
$name = $this->get_name();
|
||||
|
||||
@ -2218,12 +2210,7 @@ abstract class enrol_plugin {
|
||||
$enroller = $this->get_enroller($instance->id);
|
||||
$admin = get_admin();
|
||||
|
||||
// Some nasty hackery to get strings and dates localised for target user.
|
||||
$sessionlang = isset($SESSION->lang) ? $SESSION->lang : null;
|
||||
if (get_string_manager()->translation_exists($enroller->lang, false)) {
|
||||
$SESSION->lang = $enroller->lang;
|
||||
moodle_setlocale();
|
||||
}
|
||||
$oldforcelang = force_current_language($enroller->lang);
|
||||
|
||||
foreach($users as $key=>$info) {
|
||||
$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);
|
||||
}
|
||||
|
||||
if ($SESSION->lang !== $sessionlang) {
|
||||
$SESSION->lang = $sessionlang;
|
||||
moodle_setlocale();
|
||||
}
|
||||
force_current_language($oldforcelang);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4856,6 +4856,7 @@ function set_login_session_preferences() {
|
||||
$SESSION->justloggedin = true;
|
||||
|
||||
unset($SESSION->lang);
|
||||
unset($SESSION->forcelang);
|
||||
unset($SESSION->load_navigation_admin);
|
||||
}
|
||||
|
||||
@ -6623,7 +6624,14 @@ function clean_filename($string) {
|
||||
function current_language() {
|
||||
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.
|
||||
$return = $COURSE->lang;
|
||||
|
||||
@ -6655,14 +6663,10 @@ function current_language() {
|
||||
* @return string
|
||||
*/
|
||||
function get_parent_language($lang=null) {
|
||||
global $COURSE, $SESSION;
|
||||
|
||||
// Let's hack around the current language.
|
||||
if (!empty($lang)) {
|
||||
$oldcourselang = empty($COURSE->lang) ? '' : $COURSE->lang;
|
||||
$oldsessionlang = empty($SESSION->lang) ? '' : $SESSION->lang;
|
||||
$COURSE->lang = '';
|
||||
$SESSION->lang = $lang;
|
||||
$oldforcelang = force_current_language($lang);
|
||||
}
|
||||
|
||||
$parentlang = get_string('parentlanguage', 'langconfig');
|
||||
@ -6672,13 +6676,34 @@ function get_parent_language($lang=null) {
|
||||
|
||||
// Let's hack around the current language.
|
||||
if (!empty($lang)) {
|
||||
$COURSE->lang = $oldcourselang;
|
||||
$SESSION->lang = $oldsessionlang;
|
||||
force_current_language($oldforcelang);
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
|
@ -820,6 +820,21 @@ if (isset($_GET['lang']) and ($lang = optional_param('lang', '', PARAM_SAFEDIR))
|
||||
}
|
||||
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();
|
||||
|
||||
if (empty($CFG->lang)) {
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
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.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user