Skip to content

Commit

Permalink
MDL-13927, MDL-13938 indicate missing parent languages and allow mult…
Browse files Browse the repository at this point in the history
…iselection when importing langs
  • Loading branch information
skodak committed Mar 15, 2008
1 parent 5a79a02 commit 72ec0c3
Showing 1 changed file with 79 additions and 27 deletions.
106 changes: 79 additions & 27 deletions admin/langimport.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
admin_externalpage_setup('langimport');

$mode = optional_param('mode', 0, PARAM_INT); //phase
$pack = optional_param('pack', '', PARAM_FILE); //pack to install
$pack = optional_param('pack', array(), PARAM_FILE); //pack to install
$displaylang = $pack;
$uninstalllang = optional_param('uninstalllang', '', PARAM_FILE);
$confirm = optional_param('confirm', 0, PARAM_BOOL);
Expand Down Expand Up @@ -41,36 +41,45 @@

case INSTALLATION_OF_SELECTED_LANG: ///installation of selected language pack

if (confirm_sesskey()) {
if (confirm_sesskey() and !empty($pack)) {
set_time_limit(0);
@mkdir ($CFG->dataroot.'/temp/'); //make it in case it's a fresh install, it might not be there
@mkdir ($CFG->dataroot.'/lang/');

if ($cd = new component_installer('http://download.moodle.org', 'lang16',
$pack.'.zip', 'languages.md5', 'lang')) {
$status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
switch ($status) {

case COMPONENT_ERROR:
if ($cd->get_error() == 'remotedownloaderror') {
$a = new object();
$a->url = 'http://download.moodle.org/lang16/'.$pack.'.zip';
$a->dest= $CFG->dataroot.'/lang';
error(get_string($cd->get_error(), 'error', $a), 'langimport.php');
} else {
error(get_string($cd->get_error(), 'error'), 'langimport.php');
}
break;

case COMPONENT_INSTALLED:
$notice_ok[] = get_string('langpackinstalled','admin',$pack);
break;

case COMPONENT_UPTODATE:
break;
if (is_array($pack)) {
$packs = $pack;
} else {
$packs = array($pack);
}

foreach ($packs as $pack) {
if ($cd = new component_installer('http://download.moodle.org', 'lang16',
$pack.'.zip', 'languages.md5', 'lang')) {
$status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
switch ($status) {

case COMPONENT_ERROR:
if ($cd->get_error() == 'remotedownloaderror') {
$a = new object();
$a->url = 'http://download.moodle.org/lang16/'.$pack.'.zip';
$a->dest= $CFG->dataroot.'/lang';
error(get_string($cd->get_error(), 'error', $a), 'langimport.php');
} else {
error(get_string($cd->get_error(), 'error'), 'langimport.php');
}
break;

case COMPONENT_INSTALLED:
$notice_ok[] = get_string('langpackinstalled','admin',$pack);
break;

case COMPONENT_UPTODATE:
break;

}
} else {
notify('Had an unspecified error with the component installer, sorry.');
}
} else {
notify('Had an unspecified error with the component installer, sorry.');
}
}
break;
Expand Down Expand Up @@ -110,6 +119,7 @@
break;

case UPDATE_ALL_LANG: //1 click update for all updatable language packs
set_time_limit(0);

//0th pull a list from download.moodle.org,
//key = langname, value = md5
Expand Down Expand Up @@ -222,6 +232,28 @@

$installedlangs = get_list_of_languages(true, true);

$missingparents = array();
$oldlang = isset($SESSION->lang) ? $SESSION->lang : null; // override current lang

foreach($installedlangs as $l=>$unused) {
$SESSION->lang = $l;
$parent = get_string('parentlanguage');
if ($parent == 'en_utf8') {
continue;
}
if (strpos($parent, '[[') !== false) {
continue; // no parent
}
if (!isset($installedlangs[$parent])) {
$missingparents[$l] = $parent;
}
}
if (isset($oldlang)) {
$SESSION->lang = $oldlang;
} else {
unset($SESSION->lang);
}

if ($availablelangs = get_remote_list_of_languages()) {
$remote = 1;
} else {
Expand All @@ -245,6 +277,26 @@
notify($info, 'notifyproblem');
}

if ($missingparents) {
foreach ($missingparents as $l=>$parent) {
$a = new object();
$a->lang = $installedlangs[$l];
$a->parent = $parent;
foreach ($availablelangs as $alang) {
if ($alang[0] == $parent) {
if (substr($alang[0], -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
$shortlang = substr($alang[0], 0, -5);
} else {
$shortlang = $alang[0];
}
$a->parent = $alang[2].' ('.$shortlang.')';
}
}
$info = get_string('missinglangparent', 'admin', $a);
notify($info, 'notifyproblem');
}
}

print_box_start();
echo '<table summary="">';
echo '<tr><td align="center" valign="top">';
Expand Down Expand Up @@ -287,7 +339,7 @@
echo '<input name="sesskey" type="hidden" value="'.sesskey().'" />';
echo '<label for="pack">'.get_string('availablelangs','admin')."</label><br />\n";
if ($remote) {
echo '<select name="pack" id="pack" size="15">';
echo '<select name="pack[]" id="pack" size="15" multiple="multiple">';
}

foreach ($availablelangs as $alang) {
Expand Down

0 comments on commit 72ec0c3

Please sign in to comment.