Пример #1
0
 /**
  * Constructor
  * read the single-language file and put this in an array text.
  * the text array is two-dimensional. First dimension is the language.
  * Second dimension is the languagetopic. Content is the translation.
  * 
  * @access	public
  * @param	string		languagecode (two characters), e.g. "de", "en", "in"
  * @return	boolean 	false if reading failed
  */
 function ilLanguage($a_lang_key)
 {
     global $ilias, $log, $ilIliasIniFile, $ilUser, $ilSetting;
     $this->ilias = $ilias;
     if (!isset($log)) {
         if (is_object($ilias)) {
             require_once "./Services/Logging/classes/class.ilLog.php";
             $this->log = new ilLog(ILIAS_LOG_DIR, ILIAS_LOG_FILE, $ilias->getClientId(), ILIAS_LOG_ENABLED);
         }
     } else {
         $this->log =& $log;
     }
     $this->lang_key = $a_lang_key;
     $this->text = array();
     $this->loaded_modules = array();
     //$this->lang_path = ILIAS_ABSOLUTE_PATH.substr($this->ilias->ini->readVariable("language","path"),1);
     // if no directory was found fall back to default lang dir
     //if (!is_dir($this->lang_path))
     //{
     $this->lang_path = ILIAS_ABSOLUTE_PATH . "/lang";
     //}
     $this->cust_lang_path = ILIAS_ABSOLUTE_PATH . "/Customizing/global/lang";
     $this->lang_default = $ilIliasIniFile->readVariable("language", "default");
     if (is_object($ilSetting) && $ilSetting->get("language") != "") {
         $this->lang_default = $ilSetting->get("language");
     }
     $this->lang_user = $ilUser->prefs["language"];
     $langs = $this->getInstalledLanguages();
     if (!in_array($this->lang_key, $langs)) {
         $this->lang_key = $this->lang_default;
     }
     require_once './Services/Language/classes/class.ilCachedLanguage.php';
     $this->global_cache = ilCachedLanguage::getInstance($this->lang_key);
     if ($this->global_cache->isActive()) {
         $this->cached_modules = $this->global_cache->getTranslations();
     }
     $this->loadLanguageModule("common");
     return true;
 }
Пример #2
0
 /**
  * Save a set of translation in the database
  *
  * @access   static
  * @param    string      language key
  * @param    array       module.separator.topic => value
  * @param    array       module.separator.topic => remarks
  */
 public static function _saveValues($a_lang_key, $a_values = array(), $a_remarks = array())
 {
     global $ilDB, $lng;
     if (!is_array($a_values)) {
         return;
     }
     $save_array = array();
     $save_date = date("Y-m-d H:i:s", time());
     // read and get the global values
     require_once "./Services/Language/classes/class.ilLanguageFile.php";
     $global_file_obj = ilLanguageFile::_getGlobalLanguageFile($a_lang_key);
     $global_values = $global_file_obj->getAllValues();
     $global_comments = $global_file_obj->getAllComments();
     // 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];
             $save_array[$module][$topic] = $value;
             if ($global_values[$key] != $value or $global_comments[$key] != $a_remarks[$key]) {
                 $local_change = $save_date;
             } else {
                 $local_change = null;
             }
             ilObjLanguage::replaceLangEntry($module, $topic, $a_lang_key, $value, $local_change, $a_remarks[$key]);
         }
     }
     // save the serialized module entries in lng_modules
     foreach ($save_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_merge($arr, $entries);
         }
         ilObjLanguage::replaceLangModule($a_lang_key, $module, $entries);
     }
     require_once 'class.ilCachedLanguage.php';
     ilCachedLanguage::getInstance($a_lang_key)->flush();
 }