MDL-18797 admin/langimport.php works again for Moodle 2.0 language packs

I have prepared language packs at
http://download.moodle.org/langpack/2.0 manually for now. To be
automated once the production AMOS server is up and running.
This commit is contained in:
David Mudrak 2010-05-26 00:03:56 +00:00
parent efeedf0475
commit a9e41d3e92
2 changed files with 358 additions and 407 deletions

View File

@ -1,443 +1,394 @@
<?php
///This file only manages the installation of 2.0 lang packs.
///in downloads.moodle.org, they are store in separate directory /lang20
///in local server, they are stored in $CFG->dataroot/lang
///This helps to avoid confusion.
die('Work in progress, to be replaced by the new language update interface...');
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/filelib.php');
require_once($CFG->libdir.'/componentlib.class.php');
/**
* Fetches language packages from download.moodle.org server
*
* Language packages are available at http://download.moodle.org/langpack/2.0/
* in ZIP format together with a file languages.md5 containing thir hashes
* and meta info.
* Locally, language packs are saved into $CFG->dataroot/lang/
*
* @package core
* @copyright 2005 Yu Zhang
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
admin_externalpage_setup('langimport');
require_once(dirname(dirname(__FILE__)).'/config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/filelib.php');
require_once($CFG->libdir.'/componentlib.class.php');
if (!empty($CFG->skiplangupgrade)) {
$thisversion = '2.0'; // TODO this information should be taken from version.php or similar source
admin_externalpage_setup('langimport');
if (!empty($CFG->skiplangupgrade)) {
echo $OUTPUT->header();
echo $OUTPUT->box(get_string('langimportdisabled', 'admin'));
echo $OUTPUT->footer();
die;
}
$mode = optional_param('mode', 0, PARAM_INT); // action
$pack = optional_param('pack', array(), PARAM_SAFEDIR); // pack to install
$uninstalllang = optional_param('uninstalllang', '', PARAM_LANG); // installed pack to uninstall
$confirm = optional_param('confirm', 0, PARAM_BOOL); // uninstallation confirmation
define('INSTALLATION_OF_SELECTED_LANG', 2);
define('DELETION_OF_SELECTED_LANG', 4);
define('UPDATE_ALL_LANG', 5);
//reset and diagnose lang cache permissions
remove_dir($CFG->dataroot.'/cache/languages');
if (file_exists($CFG->dataroot.'/cache/languages')) {
print_error('cannotdeletelangcache', 'error');
}
get_string_manager()->reset_caches();
$notice_ok = array();
$notice_error = array();
if (($mode == INSTALLATION_OF_SELECTED_LANG) and confirm_sesskey() and !empty($pack)) {
set_time_limit(0);
@mkdir ($CFG->dataroot.'/temp/', $CFG->directorypermissions); //make it in case it's a fresh install, it might not be there
@mkdir ($CFG->dataroot.'/lang/', $CFG->directorypermissions);
if (is_array($pack)) {
$packs = $pack;
} else {
$packs = array($pack);
}
foreach ($packs as $pack) {
if ($cd = new component_installer('http://download.moodle.org', 'langpack/'.$thisversion, $pack.'.zip', 'languages.md5', 'lang')) {
$status = $cd->install();
switch ($status) {
case COMPONENT_ERROR:
if ($cd->get_error() == 'remotedownloaderror') {
$a = new object();
$a->url = 'http://download.moodle.org/langpack/'.$thisversion.'/'.$pack.'.zip';
$a->dest = $CFG->dataroot.'/lang';
print_error($cd->get_error(), 'error', 'langimport.php', $a);
} else {
print_error($cd->get_error(), 'error', 'langimport.php');
}
break;
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', 'langpack/'.$thisversion,
$parentlang.'.zip', 'languages.md5', 'lang')) {
$cd->install();
}
}
break;
case COMPONENT_UPTODATE:
break;
}
} else {
echo $OUTPUT->notification('Had an unspecified error with the component installer, sorry.');
}
}
}
if ($mode == DELETION_OF_SELECTED_LANG and !empty($uninstalllang)) {
if ($uninstalllang == 'en') {
$notice_error[] = 'English language pack can not be uninstalled';
} else if (!$confirm and confirm_sesskey()) {
echo $OUTPUT->header();
echo $OUTPUT->box(get_string('langimportdisabled', 'admin'));
echo $OUTPUT->confirm(get_string('uninstallconfirm', 'admin', $uninstalllang),
'langimport.php?mode='.DELETION_OF_SELECTED_LANG.'&uninstalllang='.$uninstalllang.'&confirm=1',
'langimport.php');
echo $OUTPUT->footer();
die;
} else if (confirm_sesskey()) {
$dest1 = $CFG->dataroot.'/lang/'.$uninstalllang;
$dest2 = $CFG->dirroot.'/lang/'.$uninstalllang;
$rm1 = false;
$rm2 = false;
if (file_exists($dest1)){
$rm1 = remove_dir($dest1);
}
if (file_exists($dest2)){
$rm2 = remove_dir($dest2);
}
if ($rm1 or $rm2) {
$notice_ok[] = get_string('langpackremoved','admin');
} else { //nothing deleted, possibly due to permission error
$notice_error[] = 'An error has occurred, language pack is not completely uninstalled, please check file permissions';
}
}
}
if ($mode == UPDATE_ALL_LANG) {
set_time_limit(0);
if (!$availablelangs = get_remote_list_of_languages()) {
print_error('cannotdownloadlanguageupdatelist', 'error');
}
$md5array = array(); // (string)langcode => (string)md5
foreach ($availablelangs as $alang) {
$md5array[$alang[0]] = $alang[1];
}
$mode = optional_param('mode', 0, PARAM_INT); //phase
$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);
$sitelang = optional_param('sitelangconfig', '', PARAM_FILE);
define('INSTALLATION_OF_SELECTED_LANG', 2);
define('DELETION_OF_SELECTED_LANG', 4);
define('UPDATE_ALL_LANG', 5);
$strlang = get_string('langimport','admin');
$strlanguage = get_string('language');
$strthislanguage = get_string('thislanguage', 'langconfig');
$title = $strlang;
//reset and diagnose lang cache permissions
@unlink($CFG->dataroot.'/cache/languages');
if (file_exists($CFG->dataroot.'/cache/languages')) {
print_error('cannotdeletelangcache', 'error');
}
//TODO: refresh lang cache
$notice_ok = array();
$notice_error = array();
switch ($mode){
case INSTALLATION_OF_SELECTED_LANG: ///installation of selected language pack
if (confirm_sesskey() and !empty($pack)) {
set_time_limit(0);
@mkdir ($CFG->dataroot.'/temp/', $CFG->directorypermissions); //make it in case it's a fresh install, it might not be there
@mkdir ($CFG->dataroot.'/lang/', $CFG->directorypermissions);
if (is_array($pack)) {
$packs = $pack;
} else {
$packs = array($pack);
}
foreach ($packs as $pack) {
if ($cd = new component_installer('http://download.moodle.org', 'lang20',
$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/lang20/'.$pack.'.zip';
$a->dest= $CFG->dataroot.'/lang';
print_error($cd->get_error(), 'error', 'langimport.php', $a);
} else {
print_error($cd->get_error(), 'error', 'langimport.php');
}
break;
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', 'lang20', $parentlang.'.zip', 'languages.md5', 'lang')) {
$cd->install();
}
}
break;
case COMPONENT_UPTODATE:
break;
}
} else {
echo $OUTPUT->notification('Had an unspecified error with the component installer, sorry.');
}
}
}
break;
case DELETION_OF_SELECTED_LANG: //delete a directory(ies) containing a lang pack completely
if ($uninstalllang == 'en') {
$notice_error[] = 'en can not be uninstalled!';
} else if (!$confirm && confirm_sesskey()) {
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('uninstallconfirm', 'admin', $uninstalllang),
'langimport.php?mode='.DELETION_OF_SELECTED_LANG.'&uninstalllang='.$uninstalllang.'&confirm=1',
'langimport.php');
echo $OUTPUT->footer();
die;
} else if (confirm_sesskey()) {
$dest1 = $CFG->dataroot.'/lang/'.$uninstalllang;
$dest2 = $CFG->dirroot.'/lang/'.$uninstalllang;
$rm1 = false;
$rm2 = false;
if (file_exists($dest1)){
$rm1 = remove_dir($dest1);
}
if (file_exists($dest2)){
$rm2 = remove_dir($dest2);
}
//TODO: refresh lang cache
//delete the direcotries
if ($rm1 or $rm2) {
$notice_ok[] = get_string('langpackremoved','admin');
} else { //nothing deleted, possibly due to permission error
$notice_error[] = 'An error has occurred, language pack is not completely uninstalled, please check file permissions';
}
}
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
$md5array = array();
$updated = 0; //any packs updated?
$alllangs = array_keys(get_string_manager()->get_list_of_translations(true)); //get all available langs
$lang20 = array(); //all the Moodle 1.6 unicode lang packs (updated and not updated)
$packs = array(); //all the packs that needs updating
if (!$availablelangs = get_remote_list_of_languages()) {
print_error('cannotdownloadlanguageupdatelist', 'error');
}
//and build an associative array
foreach ($availablelangs as $alang) {
$md5array[$alang[0]] = $alang[1];
}
//filtering out non-16 and unofficial packs
foreach ($alllangs as $clang) {
if (!array_key_exists($clang, $md5array)) {
$notice_ok[] = get_string('langpackupdateskipped', 'admin', $clang);
continue;
}
$dest1 = $CFG->dataroot.'/lang/'.$clang;
$dest2 = $CFG->dirroot.'/lang/'.$clang;
if (file_exists($dest1.'/langconfig.php') || file_exists($dest2.'/langconfig.php')){
$lang20[] = $clang;
}
}
//then filter out packs that have the same md5 key
foreach ($lang20 as $clang) {
if (!is_installed_lang($clang, $md5array[$clang])){
$packs[] = $clang;
}
}
@mkdir ($CFG->dataroot.'/temp/', $CFG->directorypermissions);
@mkdir ($CFG->dataroot.'/lang/', $CFG->directorypermissions);
foreach ($packs as $pack){ //for each of the remaining in the list, we
if ($pack == 'en') { // no update for en
continue;
}
//1. delete old director(ies)
$dest1 = $CFG->dataroot.'/lang/'.$pack;
$dest2 = $CFG->dirroot.'/lang/'.$pack;
$rm1 = false;
$rm2 = false;
if (file_exists($dest1)) {
if (!remove_dir($dest1)) {
$notice_error[] = 'Could not delete old directory '.$dest1.', update of '.$pack.' failed, please check permissions.';
continue;
}
}
if (file_exists($dest2)) {
if (!remove_dir($dest2)) {
$notice_error[] = 'Could not delete old directory '.$dest2.', update of '.$pack.' failed, please check permissions.';
continue;
}
}
//2. copy & unzip into new
if ($cd = new component_installer('http://download.moodle.org', 'lang20',
$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 stdClass();
$a->url = 'http://download.moodle.org/lang20/'.$pack.'.zip';
$a->dest= $CFG->dataroot.'/lang';
print_error($cd->get_error(), 'error', "", $a); // not probable
} else {
print_error($cd->get_error(), 'error'); // not probable
}
break;
case COMPONENT_UPTODATE:
//Print error string or whatever you want to do
break;
case COMPONENT_INSTALLED:
$notice_ok[] = get_string('langpackupdated', 'admin', $pack);
$updated = true;
//Print/do whatever you want
break;
default:
}
} else {
}
}
if ($updated) {
$notice_ok[] = get_string('langupdatecomplete','admin');
} else {
$notice_ok[] = get_string('nolangupdateneeded','admin');
}
break;
} //close of main switch
echo $OUTPUT->header();
$installedlangs = get_string_manager()->get_list_of_translations(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', 'langconfig');
if ($parent === 'en') {
// filter out unofficial packs
$currentlangs = array_keys(get_string_manager()->get_list_of_translations(true));
$updateablelangs = array();
foreach ($currentlangs as $clang) {
if (!array_key_exists($clang, $md5array)) {
$notice_ok[] = get_string('langpackupdateskipped', 'admin', $clang);
continue;
}
if (!isset($installedlangs[$parent])) {
$missingparents[$l] = $parent;
$dest1 = $CFG->dataroot.'/lang/'.$clang;
$dest2 = $CFG->dirroot.'/lang/'.$clang;
if (file_exists($dest1.'/langconfig.php') || file_exists($dest2.'/langconfig.php')){
$updateablelangs[] = $clang;
}
}
if (isset($oldlang)) {
$SESSION->lang = $oldlang;
// then filter out packs that have the same md5 key
$neededlangs = array(); // all the packs that needs updating
foreach ($updateablelangs as $ulang) {
if (!is_installed_lang($ulang, $md5array[$ulang])) {
$neededlangs[] = $ulang;
}
}
@mkdir ($CFG->dataroot.'/temp/', $CFG->directorypermissions);
@mkdir ($CFG->dataroot.'/lang/', $CFG->directorypermissions);
$updated = false; // any packs updated?
foreach ($neededlangs as $pack) {
if ($pack == 'en') {
continue;
}
// delete old directories
$dest1 = $CFG->dataroot.'/lang/'.$pack;
$dest2 = $CFG->dirroot.'/lang/'.$pack;
$rm1 = false;
$rm2 = false;
if (file_exists($dest1)) {
if (!remove_dir($dest1)) {
$notice_error[] = 'Could not delete old directory '.$dest1.', update of '.$pack.' failed, please check permissions.';
continue;
}
}
if (file_exists($dest2)) {
if (!remove_dir($dest2)) {
$notice_error[] = 'Could not delete old directory '.$dest2.', update of '.$pack.' failed, please check permissions.';
continue;
}
}
// copy and unzip new version
if ($cd = new component_installer('http://download.moodle.org', 'langpack/'.$thisversion, $pack.'.zip', 'languages.md5', 'lang')) {
$status = $cd->install();
switch ($status) {
case COMPONENT_ERROR:
if ($cd->get_error() == 'remotedownloaderror') {
$a = new stdClass();
$a->url = 'http://download.moodle.org/langpack/'.$thisversion.'/'.$pack.'.zip';
$a->dest = $CFG->dataroot.'/lang';
print_error($cd->get_error(), 'error', 'langimport.php', $a);
} else {
print_error($cd->get_error(), 'error', 'langimport.php');
}
break;
case COMPONENT_UPTODATE:
// should not get here
break;
case COMPONENT_INSTALLED:
$notice_ok[] = get_string('langpackupdated', 'admin', $pack);
$updated = true;
break;
}
}
}
if ($updated) {
$notice_ok[] = get_string('langupdatecomplete','admin');
} else {
unset($SESSION->lang);
$notice_ok[] = get_string('nolangupdateneeded','admin');
}
}
get_string_manager()->reset_caches();
if ($availablelangs = get_remote_list_of_languages()) {
$remote = 1;
} else {
$remote = 0; //flag for reading from remote or local
$availablelangs = get_local_list_of_languages();
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('langimport', 'admin'));
$installedlangs = get_string_manager()->get_list_of_translations(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', 'langconfig');
if (empty($parent) or ($parent === 'en')) {
continue;
}
if (!$remote) {
echo $OUTPUT->box_start();
print_string('remotelangnotavailable', 'admin', $CFG->dataroot.'/lang/');
echo $OUTPUT->box_end();
if (!isset($installedlangs[$parent])) {
$missingparents[$l] = $parent;
}
}
if (isset($oldlang)) {
$SESSION->lang = $oldlang;
} else {
unset($SESSION->lang);
}
if ($notice_ok) {
$info = implode('<br />', $notice_ok);
echo $OUTPUT->notification($info, 'notifysuccess');
}
if ($availablelangs = get_remote_list_of_languages()) {
$remote = true;
} else {
$remote = false;
$availablelangs = array();
echo $OUTPUT->box_start();
print_string('remotelangnotavailable', 'admin', $CFG->dataroot.'/lang/');
echo $OUTPUT->box_end();
}
if ($notice_error) {
$info = implode('<br />', $notice_error);
if ($notice_ok) {
$info = implode('<br />', $notice_ok);
echo $OUTPUT->notification($info, 'notifysuccess');
}
if ($notice_error) {
$info = implode('<br />', $notice_error);
echo $OUTPUT->notification($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) {
$shortlang = $alang[0];
$a->parent = $alang[2].' ('.$shortlang.')';
}
}
$info = get_string('missinglangparent', 'admin', $a);
echo $OUTPUT->notification($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) {
$shortlang = $alang[0];
$a->parent = $alang[2].' ('.$shortlang.')';
}
}
$info = get_string('missinglangparent', 'admin', $a);
echo $OUTPUT->notification($info, 'notifyproblem');
}
echo $OUTPUT->box_start();
echo html_writer::start_tag('table');
echo html_writer::start_tag('tr');
// list of installed languages
$url = new moodle_url('/admin/langimport.php', array('mode' => DELETION_OF_SELECTED_LANG));
echo html_writer::start_tag('td', array('valign' => 'top'));
echo html_writer::start_tag('form', array('id' => 'uninstallform', 'action' => $url->out(), 'method' => 'post'));
echo html_writer::start_tag('fieldset');
echo html_writer::tag('label', get_string('installedlangs','admin'), array('for' => 'uninstalllang'));
echo html_writer::empty_tag('br');
echo html_writer::select($installedlangs, 'uninstalllang', '', false, array('size' => 15));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
echo html_writer::empty_tag('br');
echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('uninstall','admin')));
echo html_writer::end_tag('fieldset');
echo html_writer::end_tag('form');
if ($remote) {
$url = new moodle_url('/admin/langimport.php', array('mode' => UPDATE_ALL_LANG));
echo html_writer::start_tag('form', array('id' => 'updateform', 'action' => $url->out(), 'method' => 'post'));
echo html_writer::tag('fieldset', html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('updatelangs','admin'))));
echo html_writer::end_tag('form');
}
echo html_writer::end_tag('td');
// list of available languages
$options = array();
foreach ($availablelangs as $alang) {
if (!empty($alang[0]) and trim($alang[0]) !== 'en' and !is_installed_lang($alang[0], $alang[1])) {
$options[$alang[0]] = $alang[2].' ('.$alang[0].')';
}
}
if (!empty($options)) {
echo html_writer::start_tag('td', array('valign' => 'top'));
$url = new moodle_url('/admin/langimport.php', array('mode' => INSTALLATION_OF_SELECTED_LANG));
echo html_writer::start_tag('form', array('id' => 'installform', 'action' => $url->out(), 'method' => 'post'));
echo html_writer::start_tag('fieldset');
echo html_writer::tag('label', get_string('availablelangs','install'), array('for' => 'pack'));
echo html_writer::empty_tag('br');
echo html_writer::select($options, 'pack[]', '', false, array('size' => 15, 'multiple' => 'multiple'));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
echo html_writer::empty_tag('br');
echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('install','admin')));
echo html_writer::end_tag('fieldset');
echo html_writer::end_tag('form');
echo html_writer::end_tag('td');
}
echo $OUTPUT->box_start();
echo '<table summary="">';
echo '<tr><td align="center" valign="top">';
echo '<form id="uninstallform" action="langimport.php?mode='.DELETION_OF_SELECTED_LANG.'" method="post">';
echo '<fieldset class="invisiblefieldset">';
echo '<input name="sesskey" type="hidden" value="'.sesskey().'" />';
echo html_writer::end_tag('tr');
echo html_writer::end_tag('table');
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
die();
/// display installed langs here
////////////////////////////////////////////////////////////////////////////////
// Local functions /////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
echo '<label for="uninstalllang">'.get_string('installedlangs','admin')."</label><br />\n";
echo '<select name="uninstalllang" id="uninstalllang" size="15">';
foreach ($installedlangs as $clang =>$ilang){
echo '<option value="'.$clang.'">'.$ilang.'</option>';
/**
* checks the md5 of the zip file, grabbed from download.moodle.org,
* against the md5 of the local language file from last update
* @param string $lang
* @param string $md5check
* @return bool
*/
function is_installed_lang($lang, $md5check) {
global $CFG;
$md5file = $CFG->dataroot.'/lang/'.$lang.'/'.$lang.'.md5';
if (file_exists($md5file)){
return (file_get_contents($md5file) == $md5check);
}
echo '</select>';
echo '<br /><input type="submit" value="'.get_string('uninstall','admin').'" />';
echo '</fieldset>';
echo '</form>';
return false;
}
if ($remote) {
echo '<form id="updateform" action="langimport.php?mode='.UPDATE_ALL_LANG.'" method="post">';
echo '<div>';
echo '<br /><input type="submit" value="'.get_string('updatelangs','admin').'" />';
echo '</div>';
echo '</form>';
}
/**
* Returns the list of available language packs from download.moodle.org
*
* @return array|bool false if can not download
*/
function get_remote_list_of_languages() {
$source = 'http://download.moodle.org/langpack/2.0/languages.md5';
$availablelangs = array();
/// Display option to change site language
/// display to be installed langs here
echo '</td><td align="center" valign="top">';
//availabe langs table
$empty = 1; //something to pring
/// if this language pack is not already installed, then we allow installation
echo '<form id="installform" method="post" action="langimport.php?mode='.INSTALLATION_OF_SELECTED_LANG.'">';
echo '<fieldset class="invisiblefieldset">';
echo '<input name="sesskey" type="hidden" value="'.sesskey().'" />';
echo '<label for="pack">'.get_string('availablelangs','install')."</label><br />\n";
if ($remote) {
echo '<select name="pack[]" id="pack" size="15" multiple="multiple">';
}
foreach ($availablelangs as $alang) {
if ($alang[0] == '') {
continue;
}
if (trim($alang[0]) != "en") {
if ($remote) {
$shortlang = $alang[0];
if (!is_installed_lang($alang[0], $alang[1])){ //if not already installed
echo '<option value="'.$alang[0].'">'.$alang[2].' ('.$shortlang.')</option>';
}
} else { //print list in local format, and instruction to install
echo '<tr><td>'.$alang[2].'</td><td><a href="http://download.moodle.org/lang20/'.$alang[0].'.zip">'.get_string('download','admin').'</a></td></tr>';
}
$empty = 0;
}
}
if ($remote) {
echo '</select>';
echo '<br /><input type="submit" value="'.$OUTPUT->larrow().' '.get_string('install','admin').'" />';
}
echo '</fieldset>';
echo '</form>';
if ($empty) {
echo '<br />';
print_string('nolanguagetodownload','admin');
}
//close available langs table
echo '</td></tr></table>';
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
/**
* Returns a list of available language packs from a
* local copy shipped with standard moodle distro
* this is for site that can't download components.
* @return array
*/
function get_local_list_of_languages() {
global $CFG;
$source = $CFG->dirroot.'/lib/languages.md5';
$availablelangs = array();
if ($fp = fopen($source, 'r')) {
while(!feof ($fp)) {
$availablelangs[] = split(',', fgets($fp,1024));
if ($content = download_file_content($source)) {
$alllines = split("\n", $content);
foreach($alllines as $line) {
if (!empty($line)){
$availablelangs[] = split(',', $line);
}
}
return $availablelangs;
}
/**
* checks the md5 of the zip file, grabbed from download.moodle.org,
* against the md5 of the local language file from last update
* @param string $lang
* @param string $md5check
* @return bool
*/
function is_installed_lang($lang, $md5check) {
global $CFG;
$md5file = $CFG->dataroot.'/lang/'.$lang.'/'.$lang.'.md5';
if (file_exists($md5file)){
return (file_get_contents($md5file) == $md5check);
}
} else {
return false;
}
/**
* Returns the latest list of available language packs from
* moodle.org
* @return array or false if can not download
*/
function get_remote_list_of_languages() {
$source = 'http://download.moodle.org/lang20/languages.md5';
$availablelangs = array();
if ($content = download_file_content($source)) {
$alllines = split("\n", $content);
foreach($alllines as $line) {
if (!empty($line)){
$availablelangs[] = split(',', $line);
}
}
return $availablelangs;
} else {
return false;
}
}
}

View File

@ -827,7 +827,7 @@ $string['recaptchaprivatekey'] = 'ReCAPTCHA private key';
$string['recaptchapublickey'] = 'ReCAPTCHA public key';
$string['registration'] = 'Registration';
$string['releasenoteslink'] = 'For information about this version of Moodle, please see the online <a target="_blank" href="{$a}">Release Notes</a>';
$string['remotelangnotavailable'] = 'Because Moodle can not connect to download.moodle.org, we are unable to do language pack installation automatically. Please download the appropriate zip file(s) from the list below, copy them to your {$a} directory and unzip them manually.';
$string['remotelangnotavailable'] = 'Because Moodle can not connect to download.moodle.org, we are unable to do language pack installation automatically. Please download the appropriate zip file(s) from http://download.moodle.org, copy them to your {$a} directory and unzip them manually.';
$string['renameerrors'] = 'Rename errors';
$string['requiredentrieschanged'] = '<strong>IMPORTANT - PLEASE READ<br/>(This warning message will only be displayed during this upgrade)</strong><br/>Due to a bug fix, the behaviour of database activities using the \'Required entries\' and \'Required entries before viewing settings\' settings will change. A more detailed explanation of the changes can be read on <a href="http://moodle.org/mod/forum/discuss.php?d=110928" target="_blank">the database module forum</a>. The expected behavior of these settings can also be read on <a href="http://docs.moodle.org/en/Adding/editing_a_database#Required_entries" target="_blank">Moodle Docs</a>.
<br/><br/>This change affects the following databases in your system: (Please save this list now, and after the upgrade, check that these activities still work the way that the teacher intends.)<br/><strong>{$a->text}</strong><br/>';