162 if (is_object($ilias))
164 require_once
"./Services/Logging/classes/class.ilLog.php";
165 $this->log =
new ilLog(ILIAS_LOG_DIR,ILIAS_LOG_FILE,$ilias->getClientId(),ILIAS_LOG_ENABLED);
173 $this->lang_key = $a_lang_key;
175 $this->text =
array();
176 $this->loaded_modules =
array();
178 $this->usage_log_enabled = self::isUsageLogEnabled();
185 $this->lang_path = ILIAS_ABSOLUTE_PATH.
"/lang";
187 $this->cust_lang_path = ILIAS_ABSOLUTE_PATH.
"/Customizing/global/lang";
189 $this->lang_default = $ilIliasIniFile->readVariable(
"language",
"default");
190 if (is_object($ilSetting) && $ilSetting->get(
"language") !=
"")
192 $this->lang_default = $ilSetting->get(
"language");
194 $this->lang_user = $ilUser->prefs[
"language"];
198 if (!in_array($this->lang_key,$langs))
203 require_once(
'./Services/Language/classes/class.ilCachedLanguage.php');
205 if ($this->global_cache->isActive()) {
206 $this->cached_modules = $this->global_cache->getTranslations();
221 return $this->lang_default ? $this->lang_default :
'en';
233 function txtlng($a_module, $a_topic, $a_language)
235 if (strcmp($a_language, $this->lang_key) == 0)
237 return $this->
txt($a_topic);
253 function txt($a_topic, $a_default_lang_fallback_mod =
"")
261 self::$used_topics[$a_topic] = $a_topic;
264 if (isset($this->text[$a_topic]))
266 $translation = $this->text[$a_topic];
269 if ($translation ==
"" && $a_default_lang_fallback_mod !=
"")
272 if($this->lang_key != $this->lang_default)
275 $a_default_lang_fallback_mod, $a_topic);
278 if($translation ==
"" || $translation ==
"-".$a_topic.
"-")
281 $a_default_lang_fallback_mod, $a_topic);
286 if ($translation ==
"")
288 if (ILIAS_LOG_ENABLED && is_object($this->log))
290 $this->log->writeLanguageLog($a_topic,$this->lang_key);
292 return "-".$a_topic.
"-";
296 if($this->usage_log_enabled)
298 self::logUsage($this->map_modules_txt[$a_topic], $a_topic);
311 return isset($this->text[$a_topic]);
318 if (in_array($a_module, $this->loaded_modules))
323 $this->loaded_modules[] = $a_module;
326 self::$used_modules[$a_module] = $a_module;
330 if (empty($this->lang_key))
335 if(is_array($this->cached_modules[$a_module])) {
336 $this->text = array_merge($this->text, $this->cached_modules[$a_module]);
338 if($this->usage_log_enabled)
340 foreach (array_keys($this->cached_modules[$a_module]) as $key)
342 $this->map_modules_txt[$key] = $a_module;
361 $q =
"SELECT * FROM lng_modules " .
362 "WHERE lang_key = ".$ilDB->quote($lang_key,
"text").
" AND module = ".
363 $ilDB->quote($a_module,
"text");
364 $r = $ilDB->query($q);
367 $new_text = unserialize(
$row[
"lang_array"]);
368 if (is_array($new_text))
370 $this->text = array_merge($this->text, $new_text);
372 if($this->usage_log_enabled)
374 foreach (array_keys($new_text) as $key)
376 $this->map_modules_txt[$key] = $a_module;
385 return self::_getInstalledLanguages();
390 include_once(
"./Services/Object/classes/class.ilObject.php");
393 foreach ($langlist as
$lang)
395 if (substr($lang[
"desc"], 0, 9) ==
"installed")
409 $set = $ilDB->query($q = sprintf(
"SELECT * FROM lng_data WHERE module = %s ".
410 "AND lang_key = %s AND identifier = %s",
411 $ilDB->quote((
string) $a_mod,
"text"), $ilDB->quote((
string) $a_lang_key,
"text"),
412 $ilDB->quote((
string) $a_id,
"text")));
413 $rec = $ilDB->fetchAssoc($set);
415 if ($rec[
"value"] !=
"")
418 self::$used_topics[$a_id] = $a_id;
419 self::$used_modules[$a_mod] = $a_mod;
421 if(self::isUsageLogEnabled())
423 self::logUsage($a_mod, $a_id);
426 return $rec[
"value"];
429 return "-".$a_id.
"-";
442 $query =
'SELECT obj_id FROM object_data '.
' '.
443 'WHERE title = '.$ilDB->quote($a_lang_key,
'text').
' '.
444 'AND type = '.$ilDB->quote(
'lng',
'text');
457 asort(self::$used_topics);
458 return self::$used_topics;
463 asort(self::$used_modules);
464 return self::$used_modules;
476 public static function getGlobalInstance()
488 (!$ilUser->getId() || $ilUser->isAnonymous())
491 require_once
'Services/Language/classes/class.ilLanguageDetection.php';
493 $language = $language_detection->detect();
495 $ilUser->setPref(
'language', $language);
496 $_GET[
'lang'] = $language;
500 if(isset(
$_POST[
'change_lang_to']) &&
$_POST[
'change_lang_to'] !=
"")
509 ($ilUser->getId() && !$ilUser->isAnonymous())
518 $langs = self::_getInstalledLanguages();
521 if($ilSetting instanceof
ilSetting && $ilSetting->
get(
'language') !=
'')
545 if (!is_object($a_tpl))
550 if (!is_array($a_lang_key))
552 $a_lang_key =
array($a_lang_key);
556 foreach ($a_lang_key as $lk)
558 $map[$lk] = $this->
txt($lk);
573 if (!is_object($a_tpl))
578 if (!is_array($a_map))
583 foreach ($a_map as $k => $v)
587 include_once(
"./Services/JSON/classes/class.ilJsonUtil.php");
588 $a_tpl->addOnloadCode(
"il.Language.setLangVar('".$k.
"', ".
ilJsonUtil::encode($v).
");");
599 protected static function logUsage($a_module, $a_identifier)
601 if($a_module !=
"" && $a_identifier !=
"")
603 self::$lng_log[$a_identifier] = $a_module;
615 protected static function isUsageLogEnabled()
618 global $ilClientIniFile,
$ilDB;
631 if(!$ilClientIniFile->variableExists(
'system',
'LANGUAGE_LOG'))
633 return $ilClientIniFile->readVariable(
'system',
'LANGUAGE_LOG') == 1;
651 foreach((
array)self::$lng_log as $identifier => $module)
653 $wave[] =
'(' . $ilDB->quote($module,
'text').
', ' . $ilDB->quote($identifier,
'text') .
')';
654 unset(self::$lng_log[$identifier]);
656 if(count($wave) == 150 || (count(self::$lng_log) == 0 && count($wave) > 0))
658 $query =
'REPLACE INTO lng_log (module, identifier) VALUES ' . implode(
', ', $wave);
659 $ilDB->manipulate(
$query);
toJSMap($a_map, ilTemplate $a_tpl=null)
Transfer text to Javascript.
toJS($a_lang_key, ilTemplate $a_tpl=null)
static get($a_var)
Get a value.
Class ilDBPdoMySQLMyISAM.
static set($a_var, $a_val)
Set a value.
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
static _lookupEntry($a_lang_key, $a_mod, $a_id)
Class ilLanguageDetection.
static logUsage($a_module, $a_identifier)
saves tupel of language module and identifier
txtlng($a_module, $a_topic, $a_language)
gets the text for a given topic in a given language if the topic is not in the list, the topic itself with "-" will be returned
exists($a_topic)
Check if language entry exists.
static encode($mixed, $suppress_native=false)
special template class to simplify handling of ITX/PEAR
redirection script todo: (a better solution should control the processing via a xml file) ...
__construct($a_lang_key)
Constructor read the single-language file and put this in an array text.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
get($a_keyword, $a_default_value=false)
get setting
loadLanguageModule($a_module)
__destruct()
destructor saves all language usages to db if log is enabled and ilDB exists
static lookupId($a_lang_key)
Lookup obj_id of language ilDB $ilDB.
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
txt($a_topic, $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _getInstalledLanguages()