/** * Show the edit screen */ function viewObject() { global $ilUser; $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_edit_items.html", "Services/Language"); // set the language to compare with $compare = $this->getPar('compare', $this->lng->getDefaultLanguage()); // get the default values if the compare language is the same if ($compare == $this->object->key) { $compare_object = $this->object->getGlobalLanguageFile(); $compare_content = $compare_object->getAllValues(); $compare_comments = $compare_object->getAllComments(); $compare_note = " " . $this->lng->txt("language_default_entries"); } // get the remarks in database $remarks = $this->object->getAllRemarks(); // page translation mode: // - the table is filtered by a list of modules and topics // - all found entries are shown on the same page if ($this->_isPageTranslation()) { $offset = 0; $limit = 0; $modules = $this->getPar("page_modules", array()); $topics = $this->getPar("page_topics", array()); if (!isset($compare_content)) { $compare_content = ilObjLanguageExt::_getValues($compare, $modules, $topics); $compare_comments = ilObjLanguageExt::_getRemarks($compare); } $translations = ilObjLanguageExt::_getValues($this->object->key, $modules, $topics); } else { $offset = $this->getPar('offset', '0'); $limit = $ilUser->getPref("hits_per_page"); $filter_mode = $this->getPar('filter_mode', 'all'); $filter_pattern = $this->getPar('filter_pattern', ''); $filter_module = $this->getPar('filter_module', 'administration'); $filter_modules = $filter_module ? array($filter_module) : array(); if (!isset($compare_content)) { $compare_content = ilObjLanguageExt::_getValues($compare, $filter_modules); $compare_comments = ilObjLanguageExt::_getRemarks($compare); } switch ($filter_mode) { case "changed": $translations = $this->object->getChangedValues($filter_modules, $filter_pattern); break; case "added": //langmode only $translations = $this->object->getAddedValues($filter_modules, $filter_pattern); break; case "unchanged": $translations = $this->object->getUnchangedValues($filter_modules, $filter_pattern); break; case "commented": $translations = $this->object->getCommentedValues($filter_modules, $filter_pattern); break; case "dbremarks": $translations = $this->object->getAllValues($filter_modules, $filter_pattern); $translations = array_intersect_key($translations, $remarks); break; case "equal": $translations = $this->object->getAllValues($filter_modules, $filter_pattern); $translations = array_intersect_assoc($translations, $compare_content); break; case "different": $translations = $this->object->getAllValues($filter_modules, $filter_pattern); $translations = array_diff_assoc($translations, $compare_content); break; case "conflicts": $former_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang'; if (!is_readable($former_file)) { ilUtil::sendFailure(sprintf($this->lng->txt("language_former_file_missing"), $former_file) . '<br />' . $this->lng->txt("language_former_file_description"), false); $translations = array(); break; } $global_file_obj = $this->object->getGlobalLanguageFile(); $former_file_obj = new ilLanguageFile($former_file); $former_file_obj->read(); $global_changes = array_diff_assoc($global_file_obj->getAllValues(), $former_file_obj->getAllValues()); if (!count($global_changes)) { ilUtil::sendInfo(sprintf($this->lng->txt("language_former_file_equal"), $former_file) . '<br />' . $this->lng->txt("language_former_file_description"), false); $translations = array(); break; } $translations = $this->object->getChangedValues($filter_modules, $filter_pattern); $translations = array_intersect_key($translations, $global_changes); break; case "all": default: $translations = $this->object->getAllValues($filter_modules, $filter_pattern); } // show the filter section $this->tpl->setCurrentBlock("filter"); // filter by language module $options = array(); $options[""] = $this->lng->txt("language_all_modules"); $modules = ilObjLanguageExt::_getModules($this->object->key); foreach ($modules as $mod) { $options[$mod] = $mod; } $this->tpl->setVariable("SELECT_MODULE", ilUtil::formSelect($filter_module, "filter_module", $options, false, true)); // filter by mode $options = array(); $options["all"] = $this->lng->txt("language_scope_global"); $options["changed"] = $this->lng->txt("language_scope_local"); if ($this->langmode) { $options["added"] = $this->lng->txt("language_scope_added"); } $options["unchanged"] = $this->lng->txt("language_scope_unchanged"); $options["equal"] = $this->lng->txt("language_scope_equal"); $options["different"] = $this->lng->txt("language_scope_different"); $options["commented"] = $this->lng->txt("language_scope_commented"); if ($this->langmode) { $options["dbremarks"] = $this->lng->txt("language_scope_dbremarks"); } $options["conflicts"] = $this->lng->txt("language_scope_conflicts"); $this->tpl->setVariable("SELECT_MODE", ilUtil::formSelect($filter_mode, "filter_mode", $options, false, true)); // filter by pattern $this->tpl->setVariable("PATTERN_NAME", "filter_pattern"); $this->tpl->setVariable("PATTERN_VALUE", ilUtil::prepareFormOutput($filter_pattern)); // and general filter variables $this->tpl->setVariable("FILTER_ACTION", $this->ctrl->getFormAction($this)); $this->tpl->setVariable("TXT_FILTER", $this->lng->txt("filter")); $this->tpl->setVariable("OFFSET_NAME", "offset"); $this->tpl->setVariable("OFFSET_VALUE", "0"); $this->tpl->setVariable("TXT_APPLY_FILTER", $this->lng->txt("apply_filter")); $this->tpl->setVariable("CMD_FILTER", "view"); $this->tpl->parseCurrentBlock(); } // show the compare section $this->tpl->setCurrentBlock("compare"); $this->tpl->setVariable("COMPARE_ACTION", $this->ctrl->getFormAction($this)); $this->tpl->setVariable("TXT_COMPARE", $this->lng->txt("language_compare")); $this->tpl->setVariable("TXT_CHANGE", $this->lng->txt("change")); $options = array(); $langlist = $this->lng->getInstalledLanguages(); foreach ($langlist as $lang_key) { $options[$lang_key] = $this->lng->txt("meta_l_" . $lang_key); } $this->tpl->setVariable("SELECT_COMPARE", ilUtil::formSelect($compare, "compare", $options, false, true, 1)); $this->tpl->setVariable("CMD_COMPARE", "view"); $this->tpl->parseCurrentBlock(); // prepare the dataset for the output table $sort_by = $this->getPar('sort_by', 'translation'); $sort_order = $this->getPar('sort_order', 'asc'); $list = array(); foreach ($translations as $name => $translation) { $keys = explode($this->lng->separator, $name); $data = array(); $data["module"] = $keys[0]; $data["topic"] = $keys[1]; $data["name"] = $name; $data["translation"] = $translation; $data["default"] = $compare_content[$name]; $data["default_comment"] = $compare_comments[$name]; $list[] = $data; } $list = ilUtil::sortArray($list, $sort_by, $sort_order); if ($limit > 0) { $list = array_slice($list, $offset, $limit); } // create and configure the table object include_once 'Services/Table/classes/class.ilTableGUI.php'; $tbl = new ilTableGUI(); $tbl->disable('title'); $tbl->setHeaderNames(array($this->lng->txt("module"), $this->lng->txt("identifier"), $this->lng->txt("meta_l_" . $this->object->key), $this->lng->txt("meta_l_" . $compare) . $compare_note)); $tbl->setHeaderVars(array("module", "topic", "translation", "default"), $this->ctrl->getParameterArray($this)); $tbl->setColumnWidth(array("10%", "20%", "40%", "30%")); $tbl->setOrderColumn($sort_by); $tbl->setOrderDirection($sort_order); $tbl->setLimit($limit); $tbl->setOffset($offset); $tbl->setMaxCount(count($translations)); // prepare the table template $tpl =& new ilTemplate("tpl.table.html", true, true); $tpl->setCurrentBlock("tbl_form_header"); $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this)); $tpl->parseCurrentBlock(); $tpl->setCurrentBlock("tbl_action_btn"); $tpl->setVariable("BTN_NAME", 'save'); $tpl->setVariable("BTN_VALUE", $this->lng->txt('save')); $tpl->parseCurrentBlock(); $tpl->setCurrentBlock("tbl_action_row"); $tpl->setVariable("COLUMN_COUNTS", "4"); $tpl->parseCurrentBlock(); // render the table rows $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.lang_items_row.html", "Services/Language"); foreach ($list as $data) { if ($this->langmode) { $tpl->setCurrentBlock('comment'); $tpl->setVariable("COM_ID", ilUtil::prepareFormOutput($data["name"] . $this->lng->separator . "comment")); $tpl->setVariable("COM_NAME", ilUtil::prepareFormOutput($data["name"] . $this->lng->separator . "comment")); $tpl->setVariable("COM_VALUE", ilUtil::prepareFormOutput($remarks[$data["name"]])); $tpl->setVariable("COM_SIZE", $this->commentsize); $tpl->setVariable("COM_MAX", 250); $tpl->setVariable("TXT_COMMENT", $this->lng->txt('comment')); $tpl->parseCurrentBlock(); } else { $tpl->setCurrentBlock('hidden_comment'); $tpl->setVariable("COM_NAME", ilUtil::prepareFormOutput($data["name"] . $this->lng->separator . "comment")); $tpl->setVariable("COM_VALUE", ilUtil::prepareFormOutput($remarks[$data["name"]])); $tpl->parseCurrentBlock(); } $tpl->setCurrentBlock("row"); $tpl->setVariable("T_ROWS", ceil(strlen($data["translation"]) / $this->inputsize)); $tpl->setVariable("T_SIZE", $this->inputsize); $tpl->setVariable("T_NAME", ilUtil::prepareFormOutput($data["name"])); $tpl->setVariable("T_USER_VALUE", ilUtil::prepareFormOutput($data["translation"])); $tpl->setVariable("MODULE", ilUtil::prepareFormOutput($data["module"])); $tpl->setVariable("TOPIC", ilUtil::prepareFormOutput($data["topic"])); $tpl->setVariable("DEFAULT_VALUE", ilUtil::prepareFormOutput($data["default"])); $tpl->setVariable("COMMENT", ilUtil::prepareFormOutput($data["default_comment"])); $tpl->parseCurrentBlock(); } // render and show the table $tbl->setTemplate($tpl); $tbl->render(); $this->tpl->setVariable("TRANSLATION_TABLE", $tpl->get()); // $this->tpl->show(); }
/** * Show the edit screen */ function viewObject() { global $tpl; // get the view table $table_gui = $this->getViewTable(); // get the remarks in database $comments = $this->object->getAllRemarks(); // set the language to compare with // get the default values if the compare language is the same $compare = $table_gui->getFilterItemByPostVar('compare')->getValue(); if ($compare == $this->object->key) { $compare_object = $this->object->getGlobalLanguageFile(); $compare_content = $compare_object->getAllValues(); $compare_comments = $compare_object->getAllComments(); } // page translation mode: // - the table is filtered by a list of modules and topics if (ilObjLanguageAccess::_isPageTranslation()) { // get the selection of modules and topics from request or session $modules = ilObjLanguageAccess::_getSavedModules(); $topics = ilObjLanguageAccess::_getSavedTopics(); // first call for translation if ($_GET['reset_offset']) { $table_gui->resetOffset(); } if (!isset($compare_content)) { $compare_content = ilObjLanguageExt::_getValues($compare, $modules, $topics); $compare_comments = ilObjLanguageExt::_getRemarks($compare); } $translations = ilObjLanguageExt::_getValues($this->object->key, $modules, $topics); // enable adding new entries $db_found = array(); foreach ($translations as $name => $translation) { $keys = explode($this->lng->separator, $name); $db_found[] = $keys[1]; } $missing_entries = array_diff($topics, $db_found); } else { $filter_mode = $table_gui->getFilterItemByPostVar('mode')->getValue(); $filter_pattern = $table_gui->getFilterItemByPostVar('pattern')->getValue(); $filter_module = $table_gui->getFilterItemByPostVar('module')->getValue(); $filter_module = $filter_module == 'all' ? '' : $filter_module; $filter_modules = $filter_module ? array($filter_module) : array(); if (!isset($compare_content)) { $compare_content = ilObjLanguageExt::_getValues($compare, $filter_modules); $compare_comments = ilObjLanguageExt::_getRemarks($compare); } switch ($filter_mode) { case "changed": $translations = $this->object->getChangedValues($filter_modules, $filter_pattern); break; case "added": //langmode only $translations = $this->object->getAddedValues($filter_modules, $filter_pattern); break; case "unchanged": $translations = $this->object->getUnchangedValues($filter_modules, $filter_pattern); break; case "commented": $translations = $this->object->getCommentedValues($filter_modules, $filter_pattern); break; case "dbremarks": $translations = $this->object->getAllValues($filter_modules, $filter_pattern); $translations = array_intersect_key($translations, $remarks); break; case "equal": $translations = $this->object->getAllValues($filter_modules, $filter_pattern); $translations = array_intersect_assoc($translations, $compare_content); break; case "different": $translations = $this->object->getAllValues($filter_modules, $filter_pattern); $translations = array_diff_assoc($translations, $compare_content); break; case "conflicts": $former_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang'; if (!is_readable($former_file)) { ilUtil::sendFailure(sprintf($this->lng->txt("language_former_file_missing"), $former_file) . '<br />' . $this->lng->txt("language_former_file_description"), false); $translations = array(); break; } $global_file_obj = $this->object->getGlobalLanguageFile(); $former_file_obj = new ilLanguageFile($former_file); $former_file_obj->read(); $global_changes = array_diff_assoc($global_file_obj->getAllValues(), $former_file_obj->getAllValues()); if (!count($global_changes)) { ilUtil::sendInfo(sprintf($this->lng->txt("language_former_file_equal"), $former_file) . '<br />' . $this->lng->txt("language_former_file_description"), false); $translations = array(); break; } $translations = $this->object->getChangedValues($filter_modules, $filter_pattern); $translations = array_intersect_key($translations, $global_changes); break; case "all": default: $translations = $this->object->getAllValues($filter_modules, $filter_pattern); } } // prepare the the data for the table $data = array(); foreach ($translations as $name => $translation) { $keys = explode($this->lng->separator, $name); $row = array(); $row["module"] = $keys[0]; $row["topic"] = $keys[1]; $row["name"] = $name; $row["translation"] = $translation; $row["comment"] = $comments[$name]; $row["default"] = $compare_content[$name]; $row["default_comment"] = $compare_comments[$name]; $data[] = $row; } // render and show the table $table_gui->setData($data); $tpl->setContent($table_gui->getHTML() . $this->buildMissingEntries($missing_entries)); }
/** * Import a language file into the ilias database * * @param string handling of existing values * ('keepall','keepnew','replace','delete') */ public function importLanguageFile($a_file, $a_mode_existing = 'keepnew') { global $ilDB, $ilErr; // read the new language file require_once "./Services/Language/classes/class.ilLanguageFile.php"; $import_file_obj = new ilLanguageFile($a_file); if (!$import_file_obj->read()) { $ilErr->raiseError($import_file_obj->getErrorMessage(), $ilErr->MESSAGE); } switch ($a_mode_existing) { // keep all existing entries case 'keepall': $to_keep = $this->getAllValues(); break; // keep existing online changes // keep existing online changes case 'keepnew': $to_keep = $this->getChangedValues(); break; // replace all existing definitions // replace all existing definitions case 'replace': $to_keep = array(); break; // delete all existing entries // delete all existing entries case 'delete': ilObjLanguage::_deleteLangData($this->key, false); $ilDB->manipulate("DELETE FROM lng_modules WHERE lang_key = " . $ilDB->quote($this->key, "text")); $to_keep = array(); break; default: return; } // process the values of the import file $to_save = array(); foreach ($import_file_obj->getAllValues() as $key => $value) { if (!isset($to_keep[$key])) { $to_save[$key] = $value; } } self::_saveValues($this->key, $to_save, $import_file_obj->getAllComments()); }