ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilLanguage Class Reference

language handling More...

+ Inheritance diagram for ilLanguage:
+ Collaboration diagram for ilLanguage:

Public Member Functions

 __construct ($a_lang_key)
 Constructor read the single-language file and put this in an array text. More...
 
 getLangKey ()
 
 getDefaultLanguage ()
 
 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 More...
 
 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 returned More...
 
 exists ($a_topic)
 Check if language entry exists. More...
 
 loadLanguageModule ($a_module)
 
 getInstalledLanguages ()
 
 getUsedTopics ()
 
 getUsedModules ()
 
 getUserLanguage ()
 
 toJS ($a_lang_key, ilTemplate $a_tpl=null)
 
 toJSMap ($a_map, ilTemplate $a_tpl=null)
 Transfer text to Javascript. More...
 
 __destruct ()
 destructor saves all language usages to db if log is enabled and ilDB exists More...
 
 __construct ($a_lang_key)
 Constructor read the single-language file and put this in an array text. More...
 
 txt ($a_topic)
 gets the text for a given topic More...
 
 getLanguages ()
 get all setup languages in the system More...
 
 installLanguages ($a_lang_keys, $a_local_keys)
 install languages More...
 
 getInstalledLanguages ()
 get already installed languages (in db) More...
 
 getInstalledLocalLanguages ()
 get already installed local languages (in db) More...
 
 getAvailableLanguages ()
 get already registered languages (in db) More...
 
 checkLanguage ($a_lang_key, $scope='')
 validate the logical structure of a lang-file More...
 
 cut_header ($content)
 Remove *.lang header information from '$content'. More...
 
 flushLanguage ($a_lang_key, $a_mode='all')
 remove language data from database More...
 
 getLocalChanges ($a_lang_key, $a_min_date="", $a_max_date="")
 get locally changed language entries More...
 
 insertLanguage ($lang_key, $scope='')
 insert language data from file in database More...
 
 getLocalLanguages ()
 Searches for the existence of *.lang.local files. More...
 
 getInstallableLanguages ()
 
 setDbHandler ($a_db_handler)
 set db handler object @string object db handler More...
 
 loadLanguageModule ()
 

Static Public Member Functions

static _getInstalledLanguages ()
 
static _lookupEntry ($a_lang_key, $a_mod, $a_id)
 
static lookupId ($a_lang_key)
 Lookup obj_id of language @global ilDB $ilDB. More...
 
static getFallbackInstance ()
 Builds a global default language instance. More...
 
static _deleteLangData ($a_lang_key, $a_keep_local_change)
 Delete languge data. More...
 
static replaceLangModule ($a_key, $a_module, $a_array)
 Replace language module array. More...
 
static replaceLangEntry ( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null)
 Replace lang entry. More...
 
static updateLangEntry ( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null)
 Update lang entry. More...
 

Data Fields

 $ilias
 
 $text = array()
 
 $lang_default = "en"
 
 $lang_user
 
 $lang_path
 
 $lang_key
 
 $lang_name
 
 $separator = "#:#"
 
 $comment_separator = "###"
 
 $loaded_modules
 

Static Protected Member Functions

static logUsage ($a_module, $a_identifier)
 saves tupel of language module and identifier More...
 

Protected Attributes

 $cached_modules = array()
 
 $map_modules_txt = array()
 
 $usage_log_enabled = false
 

Static Protected Attributes

static $used_topics = array()
 
static $used_modules = array()
 
static $lng_log = array()
 

Detailed Description

language handling

language handling for setup

this class offers the language handling for an application. it works initially on one file: languages.txt from this file the class can generate many single language files. the constructor is called with a small language abbreviation e.g. $lng = new Language("en"); the constructor reads the single-languagefile en.lang and puts this into an array. with e.g. $lng->txt("user_updated"); you can translate a lang-topic into the actual language

Author
Peter Gabriel pgabr.nosp@m.iel@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
$Id$
Todo:
Das Datefeld wird bei Aenderungen einer Sprache (update, install, deinstall) nicht richtig gesetzt!!! Die Formatfunktionen gehoeren nicht in class.Language. Die sind auch woanders einsetzbar!!! Daher->besser in class.Format

this class offers the language handling for an application. the constructor is called with a small language abbreviation e.g. $lng = new Language("en"); the constructor reads the single-languagefile en.lang and puts this into an array. with e.g. $lng->txt("user_updated"); you can translate a lang-topic into the actual language

Author
Peter Gabriel pgabr.nosp@m.iel@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
$Id$
Todo:
The DATE field is not set correctly on changes of a language (update, install, your stable). The format functions do not belong in class.Language. Those are also applicable elsewhere. Therefore, they would be better placed in class.Format

Definition at line 26 of file class.ilLanguage.php.

Constructor & Destructor Documentation

◆ __construct() [1/2]

ilLanguage::__construct (   $a_lang_key)

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

Parameters
stringlanguagecode (two characters), e.g. "de", "en", "in"
Returns
boolean false if reading failed

Definition at line 154 of file class.ilLanguage.php.

155 {
157
158 $this->ilias = $ilias;
159
160 if (!isset($log)) {
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);
164 }
165 } else {
166 $this->log =&$log;
167 }
168
169 $this->lang_key = $a_lang_key;
170
171 $this->text = array();
172 $this->loaded_modules = array();
173
174 $this->usage_log_enabled = self::isUsageLogEnabled();
175
176 //$this->lang_path = ILIAS_ABSOLUTE_PATH.substr($this->ilias->ini->readVariable("language","path"),1);
177
178 // if no directory was found fall back to default lang dir
179 //if (!is_dir($this->lang_path))
180 //{
181 $this->lang_path = ILIAS_ABSOLUTE_PATH . "/lang";
182 //}
183 $this->cust_lang_path = ILIAS_ABSOLUTE_PATH . "/Customizing/global/lang";
184
185 $this->lang_default = $ilIliasIniFile->readVariable("language", "default");
186 if (is_object($ilSetting) && $ilSetting->get("language") != "") {
187 $this->lang_default = $ilSetting->get("language");
188 }
189 $this->lang_user = $ilUser->prefs["language"];
190
191 $langs = $this->getInstalledLanguages();
192
193 if (!in_array($this->lang_key, $langs)) {
194 $this->lang_key = $this->lang_default;
195 }
196
197 require_once('./Services/Language/classes/class.ilCachedLanguage.php');
198 $this->global_cache = ilCachedLanguage::getInstance($this->lang_key);
199 if ($this->global_cache->isActive()) {
200 $this->cached_modules = $this->global_cache->getTranslations();
201 }
202
203 $this->loadLanguageModule("common");
204
205 return true;
206 }
logging
Definition: class.ilLog.php:19
redirection script todo: (a better solution should control the processing via a xml file)
global $ilSetting
Definition: privfeed.php:17
$ilIliasIniFile
$ilUser
Definition: imgupload.php:18

References $ilias, $ilIliasIniFile, $ilSetting, $ilUser, $lang_default, $log, getInstalledLanguages(), ilCachedLanguage\getInstance(), and loadLanguageModule().

+ Here is the call graph for this function:

◆ __destruct()

ilLanguage::__destruct ( )

destructor saves all language usages to db if log is enabled and ilDB exists

Definition at line 607 of file class.ilLanguage.php.

608 {
609 global $ilDB;
610
611 //case $ilDB not existing should not happen but if something went wrong it shouldn't leads to any failures
612 if (!$this->usage_log_enabled || !(($ilDB instanceof ilDBMySQL) || ($ilDB instanceof ilDBPdoMySQLMyISAM))) {
613 return;
614 }
615
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]);
619
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);
623
624 $wave = array();
625 }
626 }
627 }
MySQL Database Wrapper.
Class ilDBPdoMySQLMyISAM.
if($modEnd===false) $module
Definition: module.php:59
$query
global $ilDB

References $ilDB, $module, and $query.

◆ __construct() [2/2]

ilLanguage::__construct (   $a_lang_key)

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

Parameters
stringlanguagecode (two characters), e.g. "de", "en", "in"
Returns
boolean false if reading failed

Definition at line 100 of file class.ilLanguage.php.

101 {
102 $this->lang_key = ($a_lang_key) ? $a_lang_key : $this->lang_default;
103 $this->lang_path = ILIAS_ABSOLUTE_PATH . "/lang";
104 $this->cust_lang_path = ILIAS_ABSOLUTE_PATH . "/Customizing/global/lang";
105
106 // set lang file...
107 $txt = file($this->lang_path . "/setup_lang_sel_multi.lang");
108
109 // ...and load langdata
110 if (is_array($txt)) {
111 foreach ($txt as $row) {
112 if ($row[0] != "#") {
113 $a = explode($this->separator, trim($row));
114 $this->text[trim($a[0])] = trim($a[1]);
115 }
116 }
117 }
118
119 // set lang file...
120 $txt = file($this->lang_path . "/setup_" . $this->lang_key . ".lang");
121
122 // ...and load langdata
123 if (is_array($txt)) {
124 foreach ($txt as $row) {
125 if ($row[0] != "#") {
126 $a = explode($this->separator, trim($row));
127 $this->text[trim($a[0])] = trim($a[1]);
128 }
129 }
130
131 return true;
132 }
133
134 return false;
135 }
$txt
Definition: error.php:11

References $row, and $txt.

Member Function Documentation

◆ _deleteLangData()

static ilLanguage::_deleteLangData (   $a_lang_key,
  $a_keep_local_change 
)
static

Delete languge data.

Parameters
stringlang key

Definition at line 466 of file class.ilLanguage.php.

467 {
468 global $ilDB;
469
470 if (!$a_keep_local_change) {
471 $ilDB->manipulate("DELETE FROM lng_data WHERE lang_key = " .
472 $ilDB->quote($a_lang_key, "text"));
473 } else {
474 $ilDB->manipulate("DELETE FROM lng_data WHERE lang_key = " .
475 $ilDB->quote($a_lang_key, "text") .
476 " AND local_change IS NULL");
477 }
478 }

References $ilDB.

Referenced by flushLanguage().

+ Here is the caller graph for this function:

◆ _getInstalledLanguages()

static ilLanguage::_getInstalledLanguages ( )
static

Definition at line 368 of file class.ilLanguage.php.

369 {
370 include_once("./Services/Object/classes/class.ilObject.php");
371 $langlist = ilObject::_getObjectsByType("lng");
372
373 foreach ($langlist as $lang) {
374 if (substr($lang["desc"], 0, 9) == "installed") {
375 $languages[] = $lang["title"];
376 }
377 }
378
379 return $languages ? $languages : array();
380 }
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
$lang
Definition: consent.php:3

References $lang, and ilObject\_getObjectsByType().

Referenced by getInstalledLanguages().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lookupEntry()

static ilLanguage::_lookupEntry (   $a_lang_key,
  $a_mod,
  $a_id 
)
static

Definition at line 382 of file class.ilLanguage.php.

383 {
384 global $ilDB;
385
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")
392 ));
393 $rec = $ilDB->fetchAssoc($set);
394
395 if ($rec["value"] != "") {
396 // remember the used topics
397 self::$used_topics[$a_id] = $a_id;
398 self::$used_modules[$a_mod] = $a_mod;
399
400 if (self::isUsageLogEnabled()) {
401 self::logUsage($a_mod, $a_id);
402 }
403
404 return $rec["value"];
405 }
406
407 return "-" . $a_id . "-";
408 }
sprintf('%.4f', $callTime)
static logUsage($a_module, $a_identifier)
saves tupel of language module and identifier

References $ilDB, logUsage(), and sprintf.

Referenced by ilLinkChecker\__txt(), ilObjLTIAdministrationGUI\getConsumerForm(), ilPersonalSettingsGUI\initGeneralSettingsForm(), ilAccountMail\replacePlaceholders(), txt(), ilUserCronCheckAccounts\txt(), and txtlng().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkLanguage()

ilLanguage::checkLanguage (   $a_lang_key,
  $scope = '' 
)

validate the logical structure of a lang-file

This function checks if a lang-file of a given lang_key exists, the file has a header, and each lang-entry consists of exactly three elements (module, identifier, value).

Parameters
string$a_lang_keyinternational language key (2 digits)
string$scopeempty (global) or "local"
Returns
string $info_text message about results of check OR "1" if all checks successfully passed

Definition at line 372 of file class.ilLanguage.php.

373 {
374 if (!empty($scope)) {
375 if ($scope == 'global') {
376 $scope = '';
377 } else {
378 $scopeExtension = '.' . $scope;
379 }
380 }
381
383 if ($scope == "local") {
384 $path = $this->cust_lang_path;
385 }
386
387 $tmpPath = getcwd();
388 chdir($path);
389
390 // compute lang-file name format
391 $lang_file = "ilias_" . $a_lang_key . ".lang" . $scopeExtension;
392
393 // file check
394 if (!is_file($lang_file)) {
395 chdir($tmpPath);
396 return false;
397 }
398
399 // header check
400 if (!$content = $this->cut_header(file($lang_file))) {
401 chdir($tmpPath);
402 return false;
403 }
404
405 // check (counting) elements of each lang-entry
406 foreach ($content as $key => $val) {
407 $separated = explode($this->separator, trim($val));
408 $num = count($separated);
409
410 if ($num != 3) {
411 chdir($tmpPath);
412 return false;
413 }
414 }
415
416 chdir($tmpPath);
417
418 // no error occured
419 return true;
420 }
cut_header($content)
Remove *.lang header information from '$content'.
$key
Definition: croninfo.php:18

References $key, $lang_path, $path, and cut_header().

Referenced by installLanguages().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cut_header()

ilLanguage::cut_header (   $content)

Remove *.lang header information from '$content'.

This function seeks for a special keyword where the language information starts. If found it returns the plain language information; otherwise returns false.

Parameters
string$contentexpect an ILIAS lang-file
Returns
string $content content without header info OR false if no valid header was found @access private

Definition at line 432 of file class.ilLanguage.php.

433 {
434 foreach ($content as $key => $val) {
435 if (trim($val) == "<!-- language file start -->") {
436 return array_slice($content, $key +1);
437 }
438 }
439
440 return false;
441 }

References $key.

Referenced by checkLanguage(), and insertLanguage().

+ Here is the caller graph for this function:

◆ exists()

ilLanguage::exists (   $a_topic)

Check if language entry exists.

Parameters
object$a_topic
Returns

Definition at line 296 of file class.ilLanguage.php.

297 {
298 return isset($this->text[$a_topic]);
299 }

◆ flushLanguage()

ilLanguage::flushLanguage (   $a_lang_key,
  $a_mode = 'all' 
)

remove language data from database

Parameters
stringlanguage key
string"all" or "keep_local"

Definition at line 449 of file class.ilLanguage.php.

450 {
451 $ilDB = $this->db;
452
453 ilLanguage::_deleteLangData($a_lang_key, ($a_mode == 'keep_local'));
454
455 if ($a_mode == 'all') {
456 $ilDB->manipulate("DELETE FROM lng_modules WHERE lang_key = " .
457 $ilDB->quote($a_lang_key, "text"));
458 }
459 }
static _deleteLangData($a_lang_key, $a_keep_local_change)
Delete languge data.

References $ilDB, and _deleteLangData().

Referenced by installLanguages().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAvailableLanguages()

ilLanguage::getAvailableLanguages ( )

get already registered languages (in db)

Returns
array array with information about languages that has been registered in db

Definition at line 343 of file class.ilLanguage.php.

344 {
345 global $ilDB;
346
347 $arr = array();
348
349 $query = "SELECT * FROM object_data " .
350 "WHERE type = " . $ilDB->quote("lng", "text");
351 $r = $ilDB->query($query);
352
353 while ($row = $ilDB->fetchObject($r)) {
354 $arr[$row->title]["obj_id"] = $row->obj_id;
355 $arr[$row->title]["status"] = $row->description;
356 }
357
358 return $arr;
359 }
$r
Definition: example_031.php:79

References $ilDB, $query, $r, and $row.

Referenced by installLanguages().

+ Here is the caller graph for this function:

◆ getDefaultLanguage()

ilLanguage::getDefaultLanguage ( )

Definition at line 213 of file class.ilLanguage.php.

214 {
215 return $this->lang_default ? $this->lang_default : 'en';
216 }

◆ getFallbackInstance()

static ilLanguage::getFallbackInstance ( )
static

Builds a global default language instance.

Returns
\ilLanguage

Definition at line 453 of file class.ilLanguage.php.

454 {
455 return new self('en');
456 }

◆ getInstallableLanguages()

ilLanguage::getInstallableLanguages ( )

Definition at line 739 of file class.ilLanguage.php.

740 {
741 $setup_langs = $this->getLanguages();
742
743 $d = dir($this->lang_path);
744 $tmpPath = getcwd();
745 chdir($this->lang_path);
746
747 // get available lang-files
748 while ($entry = $d->read()) {
749 if (is_file($entry) && (preg_match("~(^ilias_.{2}\.lang$)~", $entry))) {
750 $lang_key = substr($entry, 6, 2);
751 $languages1[] = $lang_key;
752 }
753 }
754
755 //$languages = array_intersect($languages1,$setup_langs);
756
757 chdir($tmpPath);
758
759 return $languages1;
760 }
getLanguages()
get all setup languages in the system
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296

References $d, $lang_key, and getLanguages().

+ Here is the call graph for this function:

◆ getInstalledLanguages() [1/2]

ilLanguage::getInstalledLanguages ( )

Definition at line 363 of file class.ilLanguage.php.

364 {
366 }
static _getInstalledLanguages()

References _getInstalledLanguages().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstalledLanguages() [2/2]

ilLanguage::getInstalledLanguages ( )

get already installed languages (in db)

Returns
array array with inforamtion about each installed language

Definition at line 298 of file class.ilLanguage.php.

299 {
300 global $ilDB;
301
302 $arr = array();
303
304 $query = "SELECT * FROM object_data " .
305 "WHERE type = " . $ilDB->quote("lng", "text") . " " .
306 "AND " . $ilDB->like("description", "text", 'installed%');
307 $r = $ilDB->query($query);
308
309 while ($row = $ilDB->fetchObject($r)) {
310 $arr[] = $row->title;
311 }
312
313 return $arr;
314 }

References $ilDB, $query, $r, and $row.

◆ getInstalledLocalLanguages()

ilLanguage::getInstalledLocalLanguages ( )

get already installed local languages (in db)

Returns
array array with inforamtion about each installed language

Definition at line 321 of file class.ilLanguage.php.

322 {
323 global $ilDB;
324
325 $arr = array();
326
327 $query = "SELECT * FROM object_data " .
328 "WHERE type = " . $ilDB->quote("lng", "text") . " " .
329 "AND description = " . $ilDB->quote('installed_local', "text");
330 $r = $ilDB->query($query);
331
332 while ($row = $ilDB->fetchObject($r)) {
333 $arr[] = $row->title;
334 }
335
336 return $arr;
337 }

References $ilDB, $query, $r, and $row.

◆ getLangKey()

ilLanguage::getLangKey ( )

Definition at line 208 of file class.ilLanguage.php.

209 {
210 return $this->lang_key;
211 }

References $lang_key.

◆ getLanguages()

ilLanguage::getLanguages ( )

get all setup languages in the system

the functions looks for setup*.lang-files in the languagedirectory @access public

Returns
array langs

Definition at line 178 of file class.ilLanguage.php.

179 {
180 $d = dir($this->lang_path);
181 $tmpPath = getcwd();
182 chdir($this->lang_path);
183
184 // get available setup-files
185 while ($entry = $d->read()) {
186 if (is_file($entry) && (preg_match('/(^setup_.{2}\.lang$)/', $entry))) {
187 $lang_key = substr($entry, 6, 2);
188 $languages[] = $lang_key;
189 }
190 }
191
192 chdir($tmpPath);
193
194 return $languages;
195 }

References $d, and $lang_key.

Referenced by getInstallableLanguages().

+ Here is the caller graph for this function:

◆ getLocalChanges()

ilLanguage::getLocalChanges (   $a_lang_key,
  $a_min_date = "",
  $a_max_date = "" 
)

get locally changed language entries

Parameters
stringlanguage key
stringminimum change date "yyyy-mm-dd hh:mm:ss"
stringmaximum change date "yyyy-mm-dd hh:mm:ss"
Returns
array [module][identifier] => value

Definition at line 487 of file class.ilLanguage.php.

488 {
489 $ilDB = $this->db;
490
491 if ($a_min_date == "") {
492 $a_min_date = "1980-01-01 00:00:00";
493 }
494 if ($a_max_date == "") {
495 $a_max_date = "2200-01-01 00:00:00";
496 }
497
498 $q = sprintf(
499 "SELECT * FROM lng_data WHERE lang_key = %s " .
500 "AND local_change >= %s AND local_change <= %s",
501 $ilDB->quote($a_lang_key, "text"),
502 $ilDB->quote($a_min_date, "timestamp"),
503 $ilDB->quote($a_max_date, "timestamp")
504 );
505 $result = $ilDB->query($q);
506
507 $changes = array();
508 while ($row = $result->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
509 $changes[$row["module"]][$row["identifier"]] = $row["value"];
510 }
511 return $changes;
512 }
$result

References $ilDB, $result, $row, ilDBConstants\FETCHMODE_ASSOC, and sprintf.

Referenced by insertLanguage().

+ Here is the caller graph for this function:

◆ getLocalLanguages()

ilLanguage::getLocalLanguages ( )

Searches for the existence of *.lang.local files.

return $local_langs array of language keys

Definition at line 717 of file class.ilLanguage.php.

718 {
719 $local_langs = array();
720 if (is_dir($this->cust_lang_path)) {
721 $d = dir($this->cust_lang_path);
722 $tmpPath = getcwd();
723 chdir($this->cust_lang_path);
724
725 // get available .lang.local files
726 while ($entry = $d->read()) {
727 if (is_file($entry) && (preg_match("~(^ilias_.{2}\.lang.local$)~", $entry))) {
728 $lang_key = substr($entry, 6, 2);
729 $local_langs[] = $lang_key;
730 }
731 }
732
733 chdir($tmpPath);
734 }
735
736 return $local_langs;
737 }

References $d, and $lang_key.

◆ getUsedModules()

ilLanguage::getUsedModules ( )

Definition at line 438 of file class.ilLanguage.php.

439 {
440 asort(self::$used_modules);
441 return self::$used_modules;
442 }
static $used_modules

References $used_modules.

◆ getUsedTopics()

ilLanguage::getUsedTopics ( )

Definition at line 432 of file class.ilLanguage.php.

433 {
434 asort(self::$used_topics);
435 return self::$used_topics;
436 }

References $used_topics.

◆ getUserLanguage()

ilLanguage::getUserLanguage ( )

Definition at line 444 of file class.ilLanguage.php.

445 {
446 return $this->lang_user;
447 }

References $lang_user.

◆ insertLanguage()

ilLanguage::insertLanguage (   $lang_key,
  $scope = '' 
)

insert language data from file in database

Parameters
string$lang_keyinternational language key (2 digits)
string$scopeempty (global) or "local"
Returns
void

Definition at line 523 of file class.ilLanguage.php.

524 {
525 $ilDB =&$this->db;
526
527 $lang_array = array();
528
529 if (!empty($scope)) {
530 if ($scope == 'global') {
531 $scope = '';
532 } else {
533 $scopeExtension = '.' . $scope;
534 }
535 }
536
538 if ($scope == "local") {
539 $path = $this->cust_lang_path;
540 }
541
542 $tmpPath = getcwd();
543 chdir($path);
544
545 $lang_file = "ilias_" . $lang_key . ".lang" . $scopeExtension;
546
547 if ($lang_file) {
548 // initialize the array for updating lng_modules below
549 $lang_array = array();
550 $lang_array["common"] = array();
551
552 // remove header first
553 if ($content = $this->cut_header(file($lang_file))) {
554 // get the local changes from the database
555 if (empty($scope)) {
556 $local_changes = $this->getLocalChanges($lang_key);
557 } elseif ($scope == 'local') {
558 $change_date = date("Y-m-d H:i:s", time());
559 $min_date = date("Y-m-d H:i:s", filemtime($lang_file));
560 $local_changes = $this->getLocalChanges($lang_key, $min_date);
561 }
562
563 foreach ($content as $key => $val) {
564 $separated = explode($this->separator, trim($val));
565
566 //get position of the comment_separator
567 $pos = strpos($separated[2], $this->comment_separator);
568
569 if ($pos !== false) {
570 //cut comment of
571 $separated[2] = substr($separated[2], 0, $pos);
572 }
573
574 // check if the value has a local change
575 $local_value = $local_changes[$separated[0]][$separated[1]];
576
577 if (empty($scope)) {
578 if ($local_value != "" and $local_value != $separated[2]) {
579 // keep the locally changed value
580 $lang_array[$separated[0]][$separated[1]] = $local_value;
581 } else {
582 // insert a new value if no local value exists
583 // reset local_change if the values are equal
585 $separated[0],
586 $separated[1],
587 $lang_key,
588 $separated[2]
589 );
590
591 $lang_array[$separated[0]][$separated[1]] = $separated[2];
592 }
593 } elseif ($scope == 'local') {
594 if ($local_value != "") {
595 // keep a locally changed value that is newer than the local file
596 $lang_array[$separated[0]][$separated[1]] = $local_value;
597 } else {
598 // UPDATE because the global values have already been INSERTed
600 $separated[0],
601 $separated[1],
602 $lang_key,
603 $separated[2],
604 $change_date
605 );
606 $lang_array[$separated[0]][$separated[1]] = $separated[2];
607 }
608 }
609 }
610 }
611
612 foreach ($lang_array as $module => $lang_arr) {
613 if ($scope == "local") {
614 $q = "SELECT * FROM lng_modules WHERE " .
615 " lang_key = " . $ilDB->quote($this->key, "text") .
616 " AND module = " . $ilDB->quote($module, "text");
617 $set = $ilDB->query($q);
618 $row = $ilDB->fetchAssoc($set);
619 $arr2 = unserialize($row["lang_array"]);
620 if (is_array($arr2)) {
621 $lang_arr = array_merge($arr2, $lang_arr);
622 }
623 }
625 }
626 }
627
628 chdir($tmpPath);
629 }
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
static updateLangEntry( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null)
Update lang entry.
getLocalChanges($a_lang_key, $a_min_date="", $a_max_date="")
get locally changed language entries
static replaceLangEntry( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null)
Replace lang entry.
static replaceLangModule($a_key, $a_module, $a_array)
Replace language module array.

References $ilDB, $key, $lang_key, $lang_path, $module, $path, $row, cut_header(), date, getLocalChanges(), replaceLangEntry(), replaceLangModule(), and updateLangEntry().

Referenced by installLanguages().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ installLanguages()

ilLanguage::installLanguages (   $a_lang_keys,
  $a_local_keys 
)

install languages

Parameters
arrayarray with lang_keys of languages to install
Returns
boolean true on success

Definition at line 203 of file class.ilLanguage.php.

204 {
205 global $ilDB;
206
207 if (empty($a_lang_keys)) {
208 $a_lang_keys = array();
209 }
210
211 if (empty($a_local_keys)) {
212 $a_local_keys = array();
213 }
214
215 $err_lang = array();
216
217 $db_langs = $this->getAvailableLanguages();
218
219 foreach ($a_lang_keys as $lang_key) {
220 if ($this->checkLanguage($lang_key)) {
221 $this->flushLanguage($lang_key, 'keep_local');
222 $this->insertLanguage($lang_key);
223
224 if (in_array($lang_key, $a_local_keys)) {
225 if ($this->checkLanguage($lang_key, "local")) {
226 $this->insertLanguage($lang_key, "local");
227 } else {
228 $err_lang[] = $lang_key;
229 }
230 }
231
232 // register language first time install
233 if (!array_key_exists($lang_key, $db_langs)) {
234 if (in_array($lang_key, $a_local_keys)) {
235 $itype = 'installed_local';
236 } else {
237 $itype = 'installed';
238 }
239 $lid = $ilDB->nextId("object_data");
240 $query = "INSERT INTO object_data " .
241 "(obj_id,type,title,description,owner,create_date,last_update) " .
242 "VALUES " .
243 "(" .
244 $ilDB->quote($lid, "integer") . "," .
245 $ilDB->quote("lng", "text") . "," .
246 $ilDB->quote($lang_key, "text") . "," .
247 $ilDB->quote($itype, "text") . "," .
248 $ilDB->quote('-1', "integer") . "," .
249 $ilDB->now() . "," .
250 $ilDB->now() .
251 ")";
252 $this->db->manipulate($query);
253 }
254 } else {
255 $err_lang[] = $lang_key;
256 }
257 }
258
259 foreach ($db_langs as $key => $val) {
260 if (!in_array($key, $err_lang)) {
261 if (in_array($key, $a_lang_keys)) {
262 if (in_array($key, $a_local_keys)) {
263 $ld = 'installed_local';
264 } else {
265 $ld = 'installed';
266 }
267 $query = "UPDATE object_data SET " .
268 "description = " . $ilDB->quote($ld, "text") . ", " .
269 "last_update = " . $ilDB->now() . " " .
270 "WHERE obj_id = " . $ilDB->quote($val["obj_id"], "integer") . " " .
271 "AND type = " . $ilDB->quote("lng", "text");
272 $ilDB->manipulate($query);
273 } else {
274 $this->flushLanguage($key, "all");
275
276 if (substr($val["status"], 0, 9) == "installed") {
277 $query = "UPDATE object_data SET " .
278 "description = " . $ilDB->quote("not_installed", "text") . ", " .
279 "last_update = " . $ilDB->now() . " " .
280 "WHERE obj_id = " . $ilDB->quote($val["obj_id"], "integer") . " " .
281 "AND type = " . $ilDB->quote("lng", "text");
282 $ilDB->manipulate($query);
283 }
284 }
285 }
286 }
287
288 return ($err_lang) ? $err_lang : true;
289 }
getAvailableLanguages()
get already registered languages (in db)
flushLanguage($a_lang_key, $a_mode='all')
remove language data from database
insertLanguage($lang_key, $scope='')
insert language data from file in database
checkLanguage($a_lang_key, $scope='')
validate the logical structure of a lang-file

References $ilDB, $key, $lang_key, $query, checkLanguage(), flushLanguage(), getAvailableLanguages(), and insertLanguage().

+ Here is the call graph for this function:

◆ loadLanguageModule() [1/2]

ilLanguage::loadLanguageModule (   $a_module)

Definition at line 301 of file class.ilLanguage.php.

302 {
303 global $ilDB;
304
305 if (in_array($a_module, $this->loaded_modules)) {
306 return;
307 }
308
309 $this->loaded_modules[] = $a_module;
310
311 // remember the used modules globally
312 self::$used_modules[$a_module] = $a_module;
313
315
316 if (empty($this->lang_key)) {
318 }
319
320 if (is_array($this->cached_modules[$a_module])) {
321 $this->text = array_merge($this->text, $this->cached_modules[$a_module]);
322
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;
326 }
327 }
328
329 return;
330 }
331
332 /*
333 $query = "SELECT identifier,value FROM lng_data " .
334 "WHERE lang_key = '" . $lang_key."' " .
335 "AND module = '$a_module'";
336 $r = $this->ilias->db->query($query);
337
338 while ($row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
339 {
340 $this->text[$row->identifier] = $row->value;
341 }
342 */
343
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);
349
350 $new_text = unserialize($row["lang_array"]);
351 if (is_array($new_text)) {
352 $this->text = array_merge($this->text, $new_text);
353
354 if ($this->usage_log_enabled) {
355 foreach (array_keys($new_text) as $key) {
356 $this->map_modules_txt[$key] = $a_module;
357 }
358 }
359 }
360 }

References $ilDB, $key, $lang_key, $lang_user, $r, $row, and ilDBConstants\FETCHMODE_ASSOC.

◆ loadLanguageModule() [2/2]

ilLanguage::loadLanguageModule ( )

Definition at line 778 of file class.ilLanguage.php.

779 {
780 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ logUsage()

static ilLanguage::logUsage (   $a_module,
  $a_identifier 
)
staticprotected

saves tupel of language module and identifier

Parameters
string$a_module
string$a_identifier

Definition at line 570 of file class.ilLanguage.php.

571 {
572 if ($a_module != "" && $a_identifier != "") {
573 self::$lng_log[$a_identifier] = $a_module;
574 }
575 }

Referenced by _lookupEntry(), and txt().

+ Here is the caller graph for this function:

◆ lookupId()

static ilLanguage::lookupId (   $a_lang_key)
static

Lookup obj_id of language @global ilDB $ilDB.

Parameters
string$a_lang_key
Returns
int

Definition at line 416 of file class.ilLanguage.php.

417 {
418 global $ilDB;
419
420 $query = 'SELECT obj_id FROM object_data ' . ' ' .
421 'WHERE title = ' . $ilDB->quote($a_lang_key, 'text') . ' ' .
422 'AND type = ' . $ilDB->quote('lng', 'text');
423
424 $res = $ilDB->query($query);
425 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
426 return $row->obj_id;
427 }
428 return 0;
429 }
foreach($_POST as $key=> $value) $res

References $ilDB, $query, $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilStartUpGUI\getLoginPageEditorHTML(), and ilAuthLoginPageEditorTableGUI\parse().

+ Here is the caller graph for this function:

◆ replaceLangEntry()

static ilLanguage::replaceLangEntry (   $a_module,
  $a_identifier,
  $a_lang_key,
  $a_value,
  $a_local_change = null 
)
staticfinal

Replace lang entry.

Definition at line 657 of file class.ilLanguage.php.

663 {
664 global $ilDB;
665
666 $ilDB->manipulate(sprintf(
667 "DELETE FROM lng_data WHERE module = %s AND " .
668 "identifier = %s AND lang_key = %s",
669 $ilDB->quote($a_module, "text"),
670 $ilDB->quote($a_identifier, "text"),
671 $ilDB->quote($a_lang_key, "text")
672 ));
673
674 // insert a new value if no local value exists
675 // reset local_change if the values are equal
676 $ilDB->manipulate(sprintf(
677 "INSERT INTO lng_data " .
678 "(module, identifier, lang_key, value, local_change) " .
679 "VALUES (%s,%s,%s,%s,%s)",
680 $ilDB->quote($a_module, "text"),
681 $ilDB->quote($a_identifier, "text"),
682 $ilDB->quote($a_lang_key, "text"),
683 $ilDB->quote($a_value, "text"),
684 $ilDB->quote($a_local_change, "timestamp")
685 ));
686 }

References $ilDB, and sprintf.

Referenced by insertLanguage().

+ Here is the caller graph for this function:

◆ replaceLangModule()

static ilLanguage::replaceLangModule (   $a_key,
  $a_module,
  $a_array 
)
staticfinal

Replace language module array.

Definition at line 634 of file class.ilLanguage.php.

635 {
636 global $ilDB;
637
638 $ilDB->manipulate(sprintf(
639 "DELETE FROM lng_modules WHERE lang_key = %s AND module = %s",
640 $ilDB->quote($a_key, "text"),
641 $ilDB->quote($a_module, "text")
642 ));
643 /*$ilDB->manipulate(sprintf("INSERT INTO lng_modules (lang_key, module, lang_array) VALUES ".
644 "(%s,%s,%s)", $ilDB->quote($a_key, "text"),
645 $ilDB->quote($a_module, "text"),
646 $ilDB->quote(serialize($a_array), "clob")));*/
647 $ilDB->insert("lng_modules", array(
648 "lang_key" => array("text", $a_key),
649 "module" => array("text", $a_module),
650 "lang_array" => array("clob", serialize($a_array))
651 ));
652 }

References $ilDB, and sprintf.

Referenced by insertLanguage().

+ Here is the caller graph for this function:

◆ setDbHandler()

ilLanguage::setDbHandler (   $a_db_handler)

set db handler object @string object db handler

Returns
boolean true on success

Definition at line 767 of file class.ilLanguage.php.

768 {
769 if (empty($a_db_handler) or !is_object($a_db_handler)) {
770 return false;
771 }
772
773 $this->db =&$a_db_handler;
774
775 return true;
776 }

◆ toJS()

ilLanguage::toJS (   $a_lang_key,
ilTemplate  $a_tpl = null 
)

Reimplemented in ilLanguageMock.

Definition at line 519 of file class.ilLanguage.php.

520 {
521 global $tpl;
522
523 if (!is_object($a_tpl)) {
524 $a_tpl = $tpl;
525 }
526
527 if (!is_array($a_lang_key)) {
528 $a_lang_key = array($a_lang_key);
529 }
530
531 $map = array();
532 foreach ($a_lang_key as $lk) {
533 $map[$lk] = $this->txt($lk);
534 }
535 $this->toJSMap($map, $a_tpl);
536 }
$tpl
Definition: ilias.php:10
toJSMap($a_map, ilTemplate $a_tpl=null)
Transfer text to Javascript.
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...

References $tpl, toJSMap(), and txt().

+ Here is the call graph for this function:

◆ toJSMap()

ilLanguage::toJSMap (   $a_map,
ilTemplate  $a_tpl = null 
)

Transfer text to Javascript.

Parameters
array$a_maparray of key value pairs (key is text string, value is content)
ilTemplate$a_tpltemplate

Definition at line 544 of file class.ilLanguage.php.

545 {
546 global $tpl;
547
548 if (!is_object($a_tpl)) {
549 $a_tpl = $tpl;
550 }
551
552 if (!is_array($a_map)) {
553 return;
554 }
555
556 foreach ($a_map as $k => $v) {
557 if ($v != "") {
558 include_once("./Services/JSON/classes/class.ilJsonUtil.php");
559 $a_tpl->addOnloadCode("il.Language.setLangVar('" . $k . "', " . ilJsonUtil::encode($v) . ");");
560 }
561 }
562 }
static encode($mixed, $suppress_native=false)

References $tpl, and ilJsonUtil\encode().

Referenced by toJS().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ txt() [1/2]

ilLanguage::txt (   $a_topic)

gets the text for a given topic

if the topic is not in the list, the topic itself with "-" will be returned @access public

Parameters
stringtopic
Returns
string text clear-text

Definition at line 145 of file class.ilLanguage.php.

146 {
147 global $log;
148
149 if (empty($a_topic)) {
150 return "";
151 }
152
153 $translation = $this->text[$a_topic];
154
155 //get position of the comment_separator
156 $pos = strpos($translation, $this->comment_separator);
157
158 if ($pos !== false) {
159 // remove comment
160 $translation = substr($translation, 0, $pos);
161 }
162
163 if ($translation == "") {
164 $log->writeLanguageLog($a_topic, $this->lang_key);
165 return "-" . $a_topic . "-";
166 } else {
167 return $translation;
168 }
169 }

References $log.

◆ txt() [2/2]

ilLanguage::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 returned

@access public

Parameters
stringtopic
Returns
string text clear-text

Reimplemented in ilLanguageMock.

Definition at line 244 of file class.ilLanguage.php.

245 {
246 if (empty($a_topic)) {
247 return "";
248 }
249
250 // remember the used topics
251 self::$used_topics[$a_topic] = $a_topic;
252
253 $translation = "";
254 if (isset($this->text[$a_topic])) {
255 $translation = $this->text[$a_topic];
256 }
257
258 if ($translation == "" && $a_default_lang_fallback_mod != "") {
259 // #13467 - try current language first (could be missing module)
260 if ($this->lang_key != $this->lang_default) {
261 $translation = ilLanguage::_lookupEntry(
262 $this->lang_key,
263 $a_default_lang_fallback_mod,
264 $a_topic
265 );
266 }
267 // try default language last
268 if ($translation == "" || $translation == "-" . $a_topic . "-") {
269 $translation = ilLanguage::_lookupEntry(
270 $this->lang_default,
271 $a_default_lang_fallback_mod,
272 $a_topic
273 );
274 }
275 }
276
277
278 if ($translation == "") {
279 if (ILIAS_LOG_ENABLED && is_object($this->log)) {
280 $this->log->writeLanguageLog($a_topic, $this->lang_key);
281 }
282 return "-" . $a_topic . "-";
283 } else {
284 if ($this->usage_log_enabled) {
285 self::logUsage($this->map_modules_txt[$a_topic], $a_topic);
286 }
287 return $translation;
288 }
289 }
static _lookupEntry($a_lang_key, $a_mod, $a_id)

References _lookupEntry(), and logUsage().

Referenced by ilTestRandomQuestionsSrcPoolDefinitionQuantitiesCalculation\getConcurrentRuleConflictMessage(), ilAssLacAnswerIndexNotExist\getFormAlert(), ilAssLacAnswerValueNotExist\getFormAlert(), ilAssLacExpressionNotSupportedByQuestion\getFormAlert(), ilTestRandomQuestionsSrcPoolDefinitionQuantitiesCalculation\getRuleSatisfactionResultMessage(), toJS(), and txtlng().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ txtlng()

ilLanguage::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

@access public

Parameters
stringtopic
string$a_languageThe language of the output string
Returns
string text clear-text

Definition at line 227 of file class.ilLanguage.php.

228 {
229 if (strcmp($a_language, $this->lang_key) == 0) {
230 return $this->txt($a_topic);
231 } else {
232 return ilLanguage::_lookupEntry($a_language, $a_module, $a_topic);
233 }
234 }

References _lookupEntry(), and txt().

+ Here is the call graph for this function:

◆ updateLangEntry()

static ilLanguage::updateLangEntry (   $a_module,
  $a_identifier,
  $a_lang_key,
  $a_value,
  $a_local_change = null 
)
staticfinal

Update lang entry.

Definition at line 691 of file class.ilLanguage.php.

697 {
698 global $ilDB;
699
700 $ilDB->manipulate(sprintf(
701 "UPDATE lng_data " .
702 "SET value = %s, local_change = %s " .
703 "WHERE module = %s AND identifier = %s AND lang_key = %s ",
704 $ilDB->quote($a_value, "text"),
705 $ilDB->quote($a_local_change, "timestamp"),
706 $ilDB->quote($a_module, "text"),
707 $ilDB->quote($a_identifier, "text"),
708 $ilDB->quote($a_lang_key, "text")
709 ));
710 }

References $ilDB, and sprintf.

Referenced by insertLanguage().

+ Here is the caller graph for this function:

Field Documentation

◆ $cached_modules

ilLanguage::$cached_modules = array()
protected

Definition at line 127 of file class.ilLanguage.php.

◆ $comment_separator

ilLanguage::$comment_separator = "###"

Definition at line 103 of file class.ilLanguage.php.

◆ $ilias

ilLanguage::$ilias

Definition at line 34 of file class.ilLanguage.php.

Referenced by __construct().

◆ $lang_default

ilLanguage::$lang_default = "en"

Definition at line 51 of file class.ilLanguage.php.

Referenced by __construct().

◆ $lang_key

◆ $lang_name

ilLanguage::$lang_name

Definition at line 87 of file class.ilLanguage.php.

◆ $lang_path

ilLanguage::$lang_path

Definition at line 71 of file class.ilLanguage.php.

Referenced by checkLanguage(), and insertLanguage().

◆ $lang_user

ilLanguage::$lang_user

Definition at line 61 of file class.ilLanguage.php.

Referenced by getUserLanguage(), and loadLanguageModule().

◆ $lng_log

ilLanguage::$lng_log = array()
staticprotected

Definition at line 142 of file class.ilLanguage.php.

◆ $loaded_modules

ilLanguage::$loaded_modules

Definition at line 111 of file class.ilLanguage.php.

◆ $map_modules_txt

ilLanguage::$map_modules_txt = array()
protected

Definition at line 132 of file class.ilLanguage.php.

◆ $separator

ilLanguage::$separator = "#:#"

Definition at line 95 of file class.ilLanguage.php.

◆ $text

ilLanguage::$text = array()

Definition at line 42 of file class.ilLanguage.php.

◆ $usage_log_enabled

ilLanguage::$usage_log_enabled = false
protected

Definition at line 137 of file class.ilLanguage.php.

◆ $used_modules

ilLanguage::$used_modules = array()
staticprotected

Definition at line 123 of file class.ilLanguage.php.

Referenced by getUsedModules().

◆ $used_topics

ilLanguage::$used_topics = array()
staticprotected

Definition at line 117 of file class.ilLanguage.php.

Referenced by getUsedTopics().


The documentation for this class was generated from the following files: