161 if (is_object($ilias)) {
162 require_once
"./Services/Logging/classes/class.ilLog.php";
163 $this->log =
new ilLog(ILIAS_LOG_DIR, ILIAS_LOG_FILE, $ilias->getClientId(), ILIAS_LOG_ENABLED);
169 $this->lang_key = $a_lang_key;
171 $this->text =
array();
172 $this->loaded_modules =
array();
174 $this->usage_log_enabled = self::isUsageLogEnabled();
181 $this->lang_path = ILIAS_ABSOLUTE_PATH .
"/lang";
183 $this->cust_lang_path = ILIAS_ABSOLUTE_PATH .
"/Customizing/global/lang";
185 $this->lang_default = $ilIliasIniFile->readVariable(
"language",
"default");
186 if (is_object($ilSetting) && $ilSetting->get(
"language") !=
"") {
187 $this->lang_default = $ilSetting->get(
"language");
189 $this->lang_user = $ilUser->prefs[
"language"];
193 if (!in_array($this->lang_key, $langs)) {
197 require_once(
'./Services/Language/classes/class.ilCachedLanguage.php');
199 if ($this->global_cache->isActive()) {
200 $this->cached_modules = $this->global_cache->getTranslations();
215 return $this->lang_default ? $this->lang_default :
'en';
227 public function txtlng($a_module, $a_topic, $a_language)
229 if (strcmp($a_language, $this->lang_key) == 0) {
230 return $this->
txt($a_topic);
244 public function txt($a_topic, $a_default_lang_fallback_mod =
"")
246 if (empty($a_topic)) {
251 self::$used_topics[$a_topic] = $a_topic;
254 if (isset($this->text[$a_topic])) {
255 $translation = $this->text[$a_topic];
258 if ($translation ==
"" && $a_default_lang_fallback_mod !=
"") {
260 if ($this->lang_key != $this->lang_default) {
263 $a_default_lang_fallback_mod,
268 if ($translation ==
"" || $translation ==
"-" . $a_topic .
"-") {
271 $a_default_lang_fallback_mod,
278 if ($translation ==
"") {
279 if (ILIAS_LOG_ENABLED && is_object($this->log)) {
280 $this->log->writeLanguageLog($a_topic, $this->lang_key);
282 return "-" . $a_topic .
"-";
284 if ($this->usage_log_enabled) {
285 self::logUsage($this->map_modules_txt[$a_topic], $a_topic);
298 return isset($this->text[$a_topic]);
305 if (in_array($a_module, $this->loaded_modules)) {
309 $this->loaded_modules[] = $a_module;
312 self::$used_modules[$a_module] = $a_module;
316 if (empty($this->lang_key)) {
320 if (is_array($this->cached_modules[$a_module])) {
321 $this->text = array_merge($this->text, $this->cached_modules[$a_module]);
323 if ($this->usage_log_enabled) {
324 foreach (array_keys($this->cached_modules[$a_module]) as
$key) {
325 $this->map_modules_txt[
$key] = $a_module;
344 $q =
"SELECT * FROM lng_modules " .
345 "WHERE lang_key = " . $ilDB->quote(
$lang_key,
"text") .
" AND module = " .
346 $ilDB->quote($a_module,
"text");
347 $r = $ilDB->query($q);
350 $new_text = unserialize(
$row[
"lang_array"]);
351 if (is_array($new_text)) {
352 $this->text = array_merge($this->text, $new_text);
354 if ($this->usage_log_enabled) {
355 foreach (array_keys($new_text) as
$key) {
356 $this->map_modules_txt[
$key] = $a_module;
365 return self::_getInstalledLanguages();
370 include_once(
"./Services/Object/classes/class.ilObject.php");
373 foreach ($langlist as
$lang) {
374 if (substr($lang[
"desc"], 0, 9) ==
"installed") {
375 $languages[] = $lang[
"title"];
379 return $languages ? $languages :
array();
386 $set = $ilDB->query($q = sprintf(
387 "SELECT * FROM lng_data WHERE module = %s " .
388 "AND lang_key = %s AND identifier = %s",
389 $ilDB->quote((
string) $a_mod,
"text"),
390 $ilDB->quote((
string) $a_lang_key,
"text"),
391 $ilDB->quote((
string) $a_id,
"text")
393 $rec = $ilDB->fetchAssoc($set);
395 if ($rec[
"value"] !=
"") {
397 self::$used_topics[$a_id] = $a_id;
398 self::$used_modules[$a_mod] = $a_mod;
400 if (self::isUsageLogEnabled()) {
401 self::logUsage($a_mod, $a_id);
404 return $rec[
"value"];
407 return "-" . $a_id .
"-";
420 $query =
'SELECT obj_id FROM object_data ' .
' ' .
421 'WHERE title = ' . $ilDB->quote($a_lang_key,
'text') .
' ' .
422 'AND type = ' . $ilDB->quote(
'lng',
'text');
434 asort(self::$used_topics);
435 return self::$used_topics;
440 asort(self::$used_modules);
441 return self::$used_modules;
455 return new self(
'en');
462 public static function getGlobalInstance()
473 (!$ilUser->getId() || $ilUser->isAnonymous())
475 require_once
'Services/Language/classes/class.ilLanguageDetection.php';
477 $language = $language_detection->detect();
479 $ilUser->setPref(
'language', $language);
480 $_GET[
'lang'] = $language;
484 if (isset(
$_POST[
'change_lang_to']) &&
$_POST[
'change_lang_to'] !=
"") {
492 ($ilUser->getId() && !$ilUser->isAnonymous())
500 $langs = self::_getInstalledLanguages();
502 if ($ilSetting instanceof
ilSetting && $ilSetting->get(
'language') !=
'') {
523 if (!is_object($a_tpl)) {
527 if (!is_array($a_lang_key)) {
528 $a_lang_key =
array($a_lang_key);
532 foreach ($a_lang_key as $lk) {
533 $map[$lk] = $this->
txt($lk);
548 if (!is_object($a_tpl)) {
552 if (!is_array($a_map)) {
556 foreach ($a_map as $k => $v) {
558 include_once(
"./Services/JSON/classes/class.ilJsonUtil.php");
559 $a_tpl->addOnloadCode(
"il.Language.setLangVar('" . $k .
"', " .
ilJsonUtil::encode($v) .
");");
570 protected static function logUsage($a_module, $a_identifier)
572 if ($a_module !=
"" && $a_identifier !=
"") {
573 self::$lng_log[$a_identifier] = $a_module;
585 protected static function isUsageLogEnabled()
588 global $ilClientIniFile,
$ilDB;
598 if (!$ilClientIniFile->variableExists(
'system',
'LANGUAGE_LOG')) {
599 return $ilClientIniFile->readVariable(
'system',
'LANGUAGE_LOG') == 1;
616 foreach ((
array) self::$lng_log as $identifier =>
$module) {
617 $wave[] =
'(' . $ilDB->quote(
$module,
'text') .
', ' . $ilDB->quote($identifier,
'text') .
')';
618 unset(self::$lng_log[$identifier]);
620 if (count($wave) == 150 || (count(self::$lng_log) == 0 && count($wave) > 0)) {
621 $query =
'REPLACE INTO lng_log (module, identifier) VALUES ' . implode(
', ', $wave);
622 $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
if($modEnd===false) $module
exists($a_topic)
Check if language entry exists.
static encode($mixed, $suppress_native=false)
foreach($_POST as $key=> $value) $res
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
static getFallbackInstance()
Builds a global default language instance.
Create styles array
The data for the language used.
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.
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()