コード例 #1
0
 /**
  * insert language data from file into database
  * 
  * @param   string  $scope  empty (global) or "local"
  */
 function insert($scope = '')
 {
     global $ilDB;
     if (!empty($scope)) {
         if ($scope == 'global') {
             $scope = '';
         } else {
             $scopeExtension = '.' . $scope;
         }
     }
     $path = $this->lang_path;
     if ($scope == "local") {
         $path = $this->cust_lang_path;
     }
     $tmpPath = getcwd();
     chdir($path);
     $lang_file = "ilias_" . $this->key . ".lang" . $scopeExtension;
     if ($lang_file) {
         // initialize the array for updating lng_modules below
         $lang_array = array();
         $lang_array["common"] = array();
         // remove header first
         if ($content = $this->cut_header(file($lang_file))) {
             if (empty($scope)) {
                 // reset change date for a global file
                 // get all local changes for a global file
                 $change_date = null;
                 $local_changes = $this->getLocalChanges();
             } else {
                 if ($scope == 'local') {
                     // set the change date to import time for a local file
                     // get the modification date of the local file
                     // get the newer local changes for a local file
                     $change_date = date("Y-m-d H:i:s", time());
                     $min_date = date("Y-m-d H:i:s", filemtime($lang_file));
                     $local_changes = $this->getLocalChanges($min_date);
                 }
             }
             foreach ($content as $key => $val) {
                 // split the line of the language file
                 // [0]:	module
                 // [1]:	identifier
                 // [2]:	value
                 // [3]:	comment (optional)
                 $separated = explode($this->separator, trim($val));
                 $pos = strpos($separated[2], $this->comment_separator);
                 if ($pos !== false) {
                     $separated[3] = substr($separated[2], $pos + strlen($this->comment_separator));
                     $separated[2] = substr($separated[2], 0, $pos);
                 }
                 // check if the value has a local change
                 $local_value = $local_changes[$separated[0]][$separated[1]];
                 if (empty($scope)) {
                     // import of a global language file
                     if ($local_value != "" and $local_value != $separated[2]) {
                         // keep an existing and different local calue
                         $lang_array[$separated[0]][$separated[1]] = $local_value;
                     } else {
                         // check for double entries in global file
                         if ($double_checker[$separated[0]][$separated[1]][$this->key]) {
                             $this->ilias->raiseError("Duplicate Language Entry: " . $separated[0] . "-" . $separated[1] . "-" . $this->key, $this->ilias->error_obj->MESSAGE);
                         }
                         $double_checker[$separated[0]][$separated[1]][$this->key] = true;
                         // insert a new value if no local value exists
                         // reset local change date if the values are equal
                         ilObjLanguage::replaceLangEntry($separated[0], $separated[1], $this->key, $separated[2], $change_date, $separated[3]);
                         $lang_array[$separated[0]][$separated[1]] = $separated[2];
                     }
                 } else {
                     if ($scope == 'local') {
                         // import of a local language file
                         if ($local_value != "") {
                             // keep a locally changed value that is newer than the file
                             $lang_array[$separated[0]][$separated[1]] = $local_value;
                         } else {
                             // insert a new value if no global value exists
                             // (local files may have additional entries for customizations)
                             // set the change date to the import date
                             ilObjLanguage::replaceLangEntry($separated[0], $separated[1], $this->key, $separated[2], $change_date, $separated[3]);
                             $lang_array[$separated[0]][$separated[1]] = $separated[2];
                         }
                     }
                 }
             }
             $ld = "";
             if (empty($scope)) {
                 $ld = "installed";
             } else {
                 if ($scope == 'local') {
                     $ld = "installed_local";
                 }
             }
             if ($ld) {
                 $query = "UPDATE object_data SET " . "description = " . $ilDB->quote($ld, "text") . ", " . "last_update = " . $ilDB->now() . " " . "WHERE title = " . $ilDB->quote($this->key, "text") . " " . "AND type = 'lng'";
                 $ilDB->manipulate($query);
             }
         }
         foreach ($lang_array as $module => $lang_arr) {
             if ($scope == "local") {
                 $q = "SELECT * FROM lng_modules WHERE " . " lang_key = " . $ilDB->quote($this->key, "text") . " AND module = " . $ilDB->quote($module, "text");
                 $set = $ilDB->query($q);
                 $row = $ilDB->fetchAssoc($set);
                 $arr2 = unserialize($row["lang_array"]);
                 if (is_array($arr2)) {
                     $lang_arr = array_merge($arr2, $lang_arr);
                 }
             }
             ilObjLanguage::replaceLangModule($this->key, $module, $lang_arr);
         }
     }
     chdir($tmpPath);
 }
コード例 #2
0
 function saveNewEntryObject()
 {
     global $ilCtrl, $ilUser, $ilDB;
     $form = $this->initAddNewEntryForm();
     if ($form->checkInput()) {
         $mod = $form->getInput("mod");
         $id = $form->getInput("id");
         $lang = array();
         foreach ($this->lng->getInstalledLanguages() as $lang_key) {
             $trans = trim($form->getInput("trans_" . $lang_key));
             if ($trans) {
                 // add single entry
                 ilObjLanguage::replaceLangEntry($mod, $id, $lang_key, $trans, date("Y-m-d H:i:s"), $ilUser->getLogin());
                 // add to serialized module
                 $set = $ilDB->query("SELECT lang_array FROM lng_modules" . " WHERE lang_key = " . $ilDB->quote($lang_key, "text") . " AND module = " . $ilDB->quote($mod, "text"));
                 $row = $ilDB->fetchAssoc($set);
                 $entries = unserialize($row["lang_array"]);
                 if (is_array($entries)) {
                     $entries[$id] = $trans;
                     ilObjLanguage::replaceLangModule($lang_key, $mod, $entries);
                 }
             }
         }
         ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
         $ilCtrl->redirect($this, "view");
     }
     $form->setValuesByPost();
     $this->addNewEntryObject($form);
 }
コード例 #3
0
ファイル: class.ilPlugin.php プロジェクト: bheyser/qplskl
 /**
  * Update all languages
  */
 public final function updateLanguages()
 {
     global $ilCtrl;
     ilGlobalCache::flushAll();
     include_once "./Services/Language/classes/class.ilObjLanguage.php";
     $langs = $this->getAvailableLangFiles($this->getLanguageDirectory());
     $prefix = $this->getPrefix();
     foreach ($langs as $lang) {
         $txt = file($this->getLanguageDirectory() . "/" . $lang["file"]);
         $lang_array = array();
         // get language data
         if (is_array($txt)) {
             foreach ($txt as $row) {
                 if ($row[0] != "#" && strpos($row, "#:#") > 0) {
                     $a = explode("#:#", trim($row));
                     $lang_array[$prefix . "_" . trim($a[0])] = trim($a[1]);
                     ilObjLanguage::replaceLangEntry($prefix, $prefix . "_" . trim($a[0]), $lang["key"], trim($a[1]));
                     //echo "<br>-$prefix-".$prefix."_".trim($a[0])."-".$lang["key"]."-";
                 }
             }
         }
         ilObjLanguage::replaceLangModule($lang["key"], $prefix, $lang_array);
     }
 }
コード例 #4
0
 /**
  * validate the logical structure of a lang-file
  *
  * This function is similar to function checkLanguage() (see below) but checks for all
  * lang-files and outputs more helpful information.
  *
  * @return	string	system message
  */
 function checkAllLanguages()
 {
     // TODO: lng object should not be used in this class
     global $lng;
     // set path to directory where lang-files reside
     $d = dir($this->lang_path);
     $tmpPath = getcwd();
     chdir($this->lang_path);
     // for giving a message when no lang-file was found
     $found = false;
     // get available lang-files
     while ($entry = $d->read()) {
         if (is_file($entry) && ereg("(^ilias_.{2}\\.lang\$)", $entry)) {
             // textmeldung, wenn langfile gefunden wurde
             $output .= "<br/><br/>" . $lng->txt("langfile_found") . ": " . $entry;
             $content = file($entry);
             $found = true;
             $error = false;
             if ($content = ilObjLanguage::cut_header($content)) {
                 foreach ($content as $key => $val) {
                     $separated = explode($this->separator, trim($val));
                     $num = count($separated);
                     if ($num != 3) {
                         $error = true;
                         $line = $key + 37;
                         $output .= "<br/><b/>" . $lng->txt("err_in_line") . " " . $line . " !</b>&nbsp;&nbsp;";
                         $output .= $lng->txt("module") . ": " . $separated[0];
                         $output .= ", " . $lng->txt("identifier") . ": " . $separated[1];
                         $output .= ", " . $lng->txt("value") . ": " . $separated[2];
                         switch ($num) {
                             case 1:
                                 if (empty($separated[0])) {
                                     $output .= "<br/>" . $lng->txt("err_no_param") . " " . $lng->txt("check_langfile");
                                 } else {
                                     $output .= "<br/>" . $lng->txt("err_1_param") . " " . $lng->txt("check_langfile");
                                 }
                                 break;
                             case 2:
                                 $output .= "<br/>" . $lng->txt("err_2_param") . " " . $lng->txt("check_langfile");
                                 break;
                             default:
                                 $output .= "<br/>" . $lng->txt("err_over_3_param") . " " . $lng->txt("check_langfile");
                                 break;
                         }
                     }
                 }
                 if ($error) {
                     $output .= "<br/>" . $lng->txt("file_not_valid") . " " . $lng->txt("err_count_param");
                 } else {
                     $output .= "<br/>" . $lng->txt("file_valid");
                 }
             } else {
                 $output .= "<br/>" . $lng->txt("file_not_valid") . " " . $lng->txt("err_wrong_header");
             }
         }
     }
     $d->close();
     if (!$found) {
         $output .= "<br/>" . $lng->txt("err_no_langfile_found");
     }
     chdir($tmpPath);
     return $output;
 }
コード例 #5
0
 /**
  * Delete a set of translation in the database
  *
  * @access   static
  * @param    string      language key
  * @param    array       module.separator.topic => value
  */
 public static function _deleteValues($a_lang_key, $a_values = array())
 {
     global $ilDB, $lng;
     if (!is_array($a_values)) {
         return;
     }
     $delete_array = array();
     // save the single translations in lng_data
     foreach ($a_values as $key => $value) {
         $keys = explode($lng->separator, $key);
         if (count($keys) == 2) {
             $module = $keys[0];
             $topic = $keys[1];
             $delete_array[$module][$topic] = $value;
             ilObjLanguage::deleteLangEntry($module, $topic, $a_lang_key);
         }
     }
     // save the serialized module entries in lng_modules
     foreach ($delete_array as $module => $entries) {
         $set = $ilDB->query(sprintf("SELECT * FROM lng_modules " . "WHERE lang_key = %s AND module = %s", $ilDB->quote($a_lang_key, "text"), $ilDB->quote($module, "text")));
         $row = $ilDB->fetchAssoc($set);
         $arr = unserialize($row["lang_array"]);
         if (is_array($arr)) {
             $entries = array_diff_key($arr, $entries);
         }
         ilObjLanguage::replaceLangModule($a_lang_key, $module, $entries);
     }
 }
コード例 #6
0
 /**
  * set the system language
  */
 function setSystemLanguageObject()
 {
     $this->lng->loadLanguageModule("meta");
     if (!isset($_POST["id"])) {
         $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
     }
     if (count($_POST["id"]) != 1) {
         $this->ilias->raiseError($this->lng->txt("choose_only_one_language") . "<br/>" . $this->lng->txt("action_aborted"), $this->ilias->error_obj->MESSAGE);
     }
     $obj_id = $_POST["id"][0];
     $newSysLangObj = new ilObjLanguage($obj_id);
     if ($newSysLangObj->isSystemLanguage()) {
         $this->ilias->raiseError($this->lng->txt("meta_l_" . $newSysLangObj->getKey()) . " is already the system language!<br>Action aborted!", $this->ilias->error_obj->MESSAGE);
     }
     if ($newSysLangObj->isInstalled() == false) {
         $this->ilias->raiseError($this->lng->txt("meta_l_" . $newSysLangObj->getKey()) . " is not installed. Please install that language first.<br>Action aborted!", $this->ilias->error_obj->MESSAGE);
     }
     $this->ilias->setSetting("language", $newSysLangObj->getKey());
     // update ini-file
     $this->ilias->ini->setVariable("language", "default", $newSysLangObj->getKey());
     $this->ilias->ini->write();
     $this->data = $this->lng->txt("system_language") . " " . $this->lng->txt("changed_to") . " " . $this->lng->txt("meta_l_" . $newSysLangObj->getKey()) . ".";
     $this->out();
 }
コード例 #7
0
 /**
  * Fill table row
  */
 protected function fillRow($a_set)
 {
     global $lng, $rbacsystem, $ilCtrl, $ilSetting;
     // set status info (in use or systemlanguage)
     if ($a_set["status"]) {
         $status = "<span class=\"small\"> (" . $lng->txt($a_set["status"]) . ")</span>";
     }
     // set remark color
     switch ($a_set["info"]) {
         case "file_not_found":
             $remark = "<span class=\"smallred\"> " . $lng->txt($a_set["info"]) . "</span>";
             break;
         case "new_language":
             //$remark = "<span class=\"smallgreen\"> ".$lng->txt($a_set["info"])."</span>";
             break;
         default:
             $remark = "";
             break;
     }
     // show page translation
     if ($ilSetting->get("lang_ext_maintenance") and $ilSetting->get("lang_translate_" . $a_set['key'], false)) {
         $remark .= $remark ? '<br />' : '';
         $remark .= "<span class=\"smallgreen\"> " . $lng->txt('language_translation_enabled') . "</span>";
     }
     // make language name clickable
     if ($rbacsystem->checkAccess("write", $this->folder->getRefId())) {
         if ($ilSetting->get("lang_ext_maintenance") == "1") {
             if (substr($lang_data["description"], 0, 9) == "installed") {
                 $ilCtrl->setParameterByClass("ilobjlanguageextgui", "obj_id", $a_set["obj_id"]);
                 $url = $ilCtrl->getLinkTargetByClass("ilobjlanguageextgui", "");
                 $a_set["name"] = '<a href="' . $url . '">' . $a_set["name"] . '</a>';
             }
         }
     }
     if ($a_set["desc"] != "not_installed") {
         $this->tpl->setVariable("LAST_REFRESH", ilDatePresentation::formatDate(new ilDateTime($a_set["last_update"], IL_CAL_DATETIME)));
         if ($ilSetting->get("lang_ext_maintenance")) {
             $last_change = ilObjLanguage::_getLastLocalChange($a_set['key']);
             $this->tpl->setVariable("LAST_CHANGE", ilDatePresentation::formatDate(new ilDateTime($last_change, IL_CAL_DATETIME)));
         }
     }
     $this->tpl->setVariable("NR_OF_USERS", ilObjLanguage::countUsers($a_set["key"]));
     // make language name clickable
     if ($rbacsystem->checkAccess("write", $this->folder->getRefId())) {
         if ($ilSetting->get("lang_ext_maintenance") == "1") {
             if (substr($a_set["description"], 0, 9) == "installed") {
                 $ilCtrl->setParameterByClass("ilobjlanguageextgui", "obj_id", $a_set["obj_id"]);
                 $url = $ilCtrl->getLinkTargetByClass("ilobjlanguageextgui", "");
                 $a_set["name"] = '<a href="' . $url . '">' . $a_set["name"] . '</a>';
             }
         }
     }
     $this->tpl->setVariable("VAL_LANGUAGE", $a_set["name"] . $status);
     $this->tpl->setVariable("VAL_STATUS", $lng->txt($a_set["desc"]) . "<br/>" . $remark);
     $this->tpl->setVariable("OBJ_ID", $a_set["obj_id"]);
 }