. /** * Fetches language packages from download.moodle.org server * * Language packages are available at https://download.moodle.org/langpack/ * in ZIP format together with a file languages.md5 containing their hashes * and meta info. * Locally, language packs are saved into $CFG->dataroot/lang/ * * @package tool * @subpackage langimport * @copyright 2005 Yu Zhang * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require(__DIR__.'/../../../config.php'); require_once($CFG->libdir.'/adminlib.php'); admin_externalpage_setup('toollangimport'); if (empty($CFG->langotherroot)) { throw new moodle_exception('missingcfglangotherroot', 'tool_langimport'); } $mode = optional_param('mode', 0, PARAM_INT); // action $pack = optional_param_array('pack', array(), PARAM_SAFEDIR); // pack to install $uninstalllang = optional_param_array('uninstalllang', array(), PARAM_LANG);// installed pack to uninstall $confirmtounistall = optional_param('confirmtouninstall', '', PARAM_SAFEPATH); // uninstallation confirmation $purgecaches = optional_param('purgecaches', false, PARAM_BOOL); // explicit caches reset if ($purgecaches) { require_sesskey(); get_string_manager()->reset_caches(); redirect($PAGE->url); } if (!empty($CFG->skiplangupgrade)) { echo $OUTPUT->header(); echo $OUTPUT->box(get_string('langimportdisabled', 'tool_langimport')); echo $OUTPUT->single_button(new moodle_url($PAGE->url, array('purgecaches' => 1)), get_string('purgestringcaches', 'tool_langimport')); echo $OUTPUT->footer(); die; } define('INSTALLATION_OF_SELECTED_LANG', 2); define('DELETION_OF_SELECTED_LANG', 4); define('UPDATE_ALL_LANG', 5); get_string_manager()->reset_caches(); $controller = new tool_langimport\controller(); if (($mode == INSTALLATION_OF_SELECTED_LANG) and confirm_sesskey() and !empty($pack)) { core_php_time_limit::raise(); $controller->install_languagepacks($pack); } if ($mode == DELETION_OF_SELECTED_LANG and (!empty($uninstalllang) or !empty($confirmtounistall))) { // Actually deleting languages, languages to delete are passed as GET parameter as string // ...need to populate them to array. if (empty($uninstalllang)) { $uninstalllang = explode('/', $confirmtounistall); } if (in_array('en', $uninstalllang)) { // TODO. $controller->errors[] = get_string('noenglishuninstall', 'tool_langimport'); } else if (empty($confirmtounistall) and confirm_sesskey()) { // User chose langs to be deleted, show confirmation. echo $OUTPUT->header(); echo $OUTPUT->confirm(get_string('uninstallconfirm', 'tool_langimport', implode(', ', $uninstalllang)), new moodle_url($PAGE->url, array( 'mode' => DELETION_OF_SELECTED_LANG, 'confirmtouninstall' => implode('/', $uninstalllang), )), $PAGE->url); echo $OUTPUT->footer(); die; } else if (confirm_sesskey()) { // Deleting languages. foreach ($uninstalllang as $ulang) { $controller->uninstall_language($ulang); } } } if ($mode == UPDATE_ALL_LANG) { core_php_time_limit::raise(); $controller->update_all_installed_languages(); } get_string_manager()->reset_caches(); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('langimport', 'tool_langimport')); $installedlangs = get_string_manager()->get_list_of_translations(true); $locale = new \tool_langimport\locale(); $missinglocales = ''; $missingparents = array(); foreach ($installedlangs as $installedlang => $langpackname) { // Check locale availability. if (!$locale->check_locale_availability($installedlang)) { $missinglocales .= '