MDL-17573 added automatic downloading of parent languages

This commit is contained in:
skodak 2009-02-08 22:33:54 +00:00
parent c33b83e77c
commit 07f6711889
2 changed files with 26 additions and 2 deletions

View File

@ -78,6 +78,12 @@
case COMPONENT_INSTALLED:
$notice_ok[] = get_string('langpackinstalled','admin',$pack);
if ($parentlang = get_parent_language($pack)) {
// install also parent pack if specified
if ($cd = new component_installer('http://download.moodle.org', 'lang16', $parentlang.'.zip', 'languages.md5', 'lang')) {
$cd->install();
}
}
break;
case COMPONENT_UPTODATE:

View File

@ -5144,13 +5144,31 @@ function current_language() {
/**
* Returns parent language of current active language if defined
* @param string $lang null means current language
* @return string
*/
function get_parent_language() {
function get_parent_language($lang=null) {
global $COURSE, $SESSION;
//let's hack around the current language
if (!empty($lang)) {
$old_course_lang = empty($COURSE->lang) ? '' : $COURSE->lang;
$old_session_lang = empty($SESSION->lang) ? '' : $SESSION->lang;
$COURSE->lang = '';
$SESSION->lang = $lang;
}
$parentlang = get_string('parentlanguage');
if ($parentlang === '[[parentlanguage]]' or strpos($parentlang, '<') !== false) {
return '';
$parentlang = '';
}
//let's hack around the current language
if (!empty($lang)) {
$COURSE->lang = $old_course_lang;
$SESSION->lang = $old_session_lang;
}
return $parentlang;
}