Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00047 class ilLanguage
00048 {
00055 var $ilias;
00056
00063 var $text;
00064
00072 var $lang_default;
00073
00082 var $lang_user;
00083
00092 var $lang_path;
00093
00100 var $lang_key;
00101
00108 var $lang_name;
00109
00116 var $separator = "#:#";
00117
00124 var $comment_separator = "###";
00125
00132 var $loaded_modules;
00133
00144 function ilLanguage($a_lang_key)
00145 {
00146 global $ilias,$log;
00147
00148
00149 $this->ilias =& $ilias;
00150
00151 if (!isset($log))
00152 {
00153 $this->log = new ilLog(ILIAS_LOG_DIR,ILIAS_LOG_FILE,$ilias->getClientId(),ILIAS_LOG_ENABLED);
00154 }
00155 else
00156 {
00157 $this->log =& $log;
00158 }
00159
00160 $this->lang_key = $a_lang_key;
00161 $this->text = array();
00162 $this->loaded_modules = array();
00163 $this->lang_path = ILIAS_ABSOLUTE_PATH.substr($this->ilias->ini->readVariable("language","path"),1);
00164
00165
00166 if (!is_dir($this->lang_path))
00167 {
00168 $this->lang_path = ILIAS_ABSOLUTE_PATH."/lang";
00169 }
00170
00171 $this->lang_default = $this->ilias->ini->readVariable("language","default");
00172 $this->lang_user = $this->ilias->account->prefs["language"];
00173
00174 $langs = $this->getInstalledLanguages();
00175
00176 if (!in_array($this->lang_key,$langs))
00177 {
00178 $this->lang_key = $this->lang_default;
00179 }
00180
00181 $this->loadLanguageModule("common");
00182
00183 return true;
00184 }
00185
00186 function getLangKey()
00187 {
00188 return $this->lang_key;
00189 }
00190
00191 function getDefaultLanguage()
00192 {
00193 return $this->lang_default;
00194 }
00195
00205 function txtlng($a_module, $a_topic, $a_language)
00206 {
00207 if (strcmp($a_language, $this->lang_key) == 0)
00208 {
00209 return $this->txt($a_topic);
00210 }
00211 else
00212 {
00213 $query = sprintf("SELECT value FROM lng_data WHERE lang_key = %s AND module = %s AND identifier = %s",
00214 $this->ilias->db->quote($a_language . ""),
00215 $this->ilias->db->quote($a_module . ""),
00216 $this->ilias->db->quote($a_topic . "")
00217 );
00218 $r = $this->ilias->db->query($query);
00219
00220 if ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00221 {
00222 return $row->value;
00223 }
00224 else
00225 {
00226 return "-".$a_topic."-";
00227 }
00228 }
00229 }
00230
00239 function txt($a_topic)
00240 {
00241 if (empty($a_topic))
00242 {
00243 return "";
00244 }
00245 $translation = $this->text[$a_topic];
00246
00247 if ($translation == "")
00248 {
00249 if (ILIAS_LOG_ENABLED)
00250 {
00251 $this->log->writeLanguageLog($a_topic,$this->lang_key);
00252 }
00253
00254 return "-".$a_topic."-";
00255 }
00256 else
00257 {
00258 return $translation;
00259 }
00260 }
00261
00262 function loadLanguageModule ($a_module)
00263 {
00264 if (in_array($a_module, $this->loaded_modules))
00265 {
00266 return;
00267 }
00268
00269 $this->loaded_modules[] = $a_module;
00270
00271 $lang_key = $this->lang_key;
00272
00273 if (empty($this->lang_key))
00274 {
00275 $lang_key = $this->lang_user;
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 $query = "SELECT * FROM lng_modules " .
00290 "WHERE lang_key = '".$lang_key."' " .
00291 "AND module = '$a_module'";
00292 $r = $this->ilias->db->query($query);
00293 $row = $r->fetchRow(DB_FETCHMODE_ASSOC);
00294
00295 $new_text = unserialize($row["lang_array"]);
00296 if (is_array($new_text))
00297 {
00298 $this->text = array_merge($this->text, $new_text);
00299 }
00300 }
00301
00302
00303 function getInstalledLanguages()
00304 {
00305 $langlist = getObjectList("lng");
00306
00307 foreach ($langlist as $lang)
00308 {
00309 if (substr($lang["desc"], 0, 9) == "installed")
00310 {
00311 $languages[] = $lang["title"];
00312 }
00313
00314 }
00315
00316 return $languages;
00317 }
00318
00319 function _lookupEntry($a_lang_key, $a_mod, $a_id)
00320 {
00321 global $ilDB;
00322
00323 $q = "SELECT * FROM lng_data WHERE".
00324 " module = ".$ilDB->quote($a_mod).
00325 " AND lang_key =".$ilDB->quote($a_lang_key).
00326 " AND identifier =".$ilDB->quote($a_id);
00327
00328 $set = $ilDB->query($q);
00329
00330 $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00331
00332 if ($rec["value"] != "")
00333 {
00334 return $rec["value"];
00335 }
00336
00337 return "-".$a_id."-";
00338 }
00339 }
00340 ?>