ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
ilLanguage Class Reference

language handling More...

+ Collaboration diagram for ilLanguage:

Public Member Functions

 ilLanguage ($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 ()
 
 ilLanguage ($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 object db handler More...
 
 loadLanguageModule ()
 

Static Public Member Functions

static _lookupEntry ($a_lang_key, $a_mod, $a_id)
 
static lookupId ($a_lang_key)
 Lookup obj_id of language ilDB $ilDB. 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
 

Protected Attributes

 $cached_modules = array()
 

Static Protected Attributes

static $used_topics = array()
 
static $used_modules = 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.

Member Function Documentation

◆ _deleteLangData()

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

Delete languge data.

Parameters
stringlang key

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

References $ilDB.

Referenced by flushLanguage().

518  {
519  global $ilDB;
520 
521  if (!$a_keep_local_change)
522  {
523  $ilDB->manipulate("DELETE FROM lng_data WHERE lang_key = ".
524  $ilDB->quote($a_lang_key, "text"));
525  }
526  else
527  {
528  $ilDB->manipulate("DELETE FROM lng_data WHERE lang_key = ".
529  $ilDB->quote($a_lang_key, "text").
530  " AND local_change IS NULL");
531  }
532  }
global $ilDB
+ Here is the caller graph for this function:

◆ _lookupEntry()

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

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

References $ilDB.

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

363  {
364  global $ilDB;
365 
366  $set = $ilDB->query($q = sprintf("SELECT * FROM lng_data WHERE module = %s ".
367  "AND lang_key = %s AND identifier = %s",
368  $ilDB->quote((string) $a_mod, "text"), $ilDB->quote((string) $a_lang_key, "text"),
369  $ilDB->quote((string) $a_id, "text")));
370  $rec = $ilDB->fetchAssoc($set);
371 
372  if ($rec["value"] != "")
373  {
374  // remember the used topics
375  self::$used_topics[$a_id] = $a_id;
376  self::$used_modules[$a_mod] = $a_mod;
377 
378  return $rec["value"];
379  }
380 
381  return "-".$a_id."-";
382  }
global $ilDB
+ 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 411 of file class.ilLanguage.php.

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

Referenced by installLanguages().

412  {
413  if (!empty($scope))
414  {
415  if ($scope == 'global')
416  {
417  $scope = '';
418  }
419  else
420  {
421  $scopeExtension = '.' . $scope;
422  }
423  }
424 
426  if ($scope == "local")
427  {
428  $path = $this->cust_lang_path;
429  }
430 
431  $tmpPath = getcwd();
432  chdir($path);
433 
434  // compute lang-file name format
435  $lang_file = "ilias_" . $a_lang_key . ".lang" . $scopeExtension;
436 
437  // file check
438  if (!is_file($lang_file))
439  {
440  chdir($tmpPath);
441  return false;
442  }
443 
444  // header check
445  if (!$content = $this->cut_header(file($lang_file)))
446  {
447  chdir($tmpPath);
448  return false;
449  }
450 
451  // check (counting) elements of each lang-entry
452  foreach ($content as $key => $val)
453  {
454  $separated = explode($this->separator, trim($val));
455  $num = count($separated);
456 
457  if ($num != 3)
458  {
459  chdir($tmpPath);
460  return false;
461  }
462  }
463 
464  chdir($tmpPath);
465 
466  // no error occured
467  return true;
468  }
cut_header($content)
Remove *.lang header information from '$content'.
$path
Definition: index.php:22
+ 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 private

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

Referenced by checkLanguage(), and insertLanguage().

481  {
482  foreach ($content as $key => $val)
483  {
484  if (trim($val) == "<!-- language file start -->")
485  {
486  return array_slice($content,$key +1);
487  }
488  }
489 
490  return false;
491  }
+ 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 287 of file class.ilLanguage.php.

288  {
289  return isset($this->text[$a_topic]);
290  }

◆ 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 499 of file class.ilLanguage.php.

References $ilDB, and _deleteLangData().

Referenced by installLanguages().

500  {
501  $ilDB = $this->db;
502 
503  ilLanguage::_deleteLangData($a_lang_key, ($a_mode == 'keep_local'));
504 
505  if ($a_mode == 'all')
506  {
507  $ilDB->manipulate("DELETE FROM lng_modules WHERE lang_key = ".
508  $ilDB->quote($a_lang_key, "text"));
509  }
510  }
static _deleteLangData($a_lang_key, $a_keep_local_change)
Delete languge data.
global $ilDB
+ 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 381 of file class.ilLanguage.php.

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

Referenced by installLanguages().

382  {
383  global $ilDB;
384 
385  $arr = array();
386 
387  $query = "SELECT * FROM object_data ".
388  "WHERE type = ".$ilDB->quote("lng", "text");
389  $r = $ilDB->query($query);
390 
391  while ($row = $ilDB->fetchObject($r))
392  {
393  $arr[$row->title]["obj_id"] = $row->obj_id;
394  $arr[$row->title]["status"] = $row->description;
395  }
396 
397  return $arr;
398  }
global $ilDB
$r
+ Here is the caller graph for this function:

◆ getDefaultLanguage()

ilLanguage::getDefaultLanguage ( )

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

202  {
203  return $this->lang_default ? $this->lang_default : 'en';
204  }

◆ getInstallableLanguages()

ilLanguage::getInstallableLanguages ( )

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

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

790  {
791  $setup_langs = $this->getLanguages();
792 
793  $d = dir($this->lang_path);
794  $tmpPath = getcwd();
795  chdir ($this->lang_path);
796 
797  // get available lang-files
798  while ($entry = $d->read())
799  {
800  if (is_file($entry) && (ereg ("(^ilias_.{2}\.lang$)", $entry)))
801  {
802  $lang_key = substr($entry,6,2);
803  $languages1[] = $lang_key;
804  }
805  }
806 
807  //$languages = array_intersect($languages1,$setup_langs);
808 
809  chdir($tmpPath);
810 
811  return $languages1;
812  }
getLanguages()
get all setup languages in the system
+ Here is the call graph for this function:

◆ getInstalledLanguages() [1/2]

ilLanguage::getInstalledLanguages ( )

get already installed languages (in db)

Returns
array array with inforamtion about each installed language

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

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

335  {
336  global $ilDB;
337 
338  $arr = array();
339 
340  $query = "SELECT * FROM object_data ".
341  "WHERE type = ".$ilDB->quote("lng", "text")." ".
342  "AND ".$ilDB->like("description", "text", 'installed%');
343  $r = $ilDB->query($query);
344 
345  while ($row = $ilDB->fetchObject($r))
346  {
347  $arr[] = $row->title;
348  }
349 
350  return $arr;
351  }
global $ilDB
$r

◆ getInstalledLanguages() [2/2]

ilLanguage::getInstalledLanguages ( )

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

References $lang, and ilObject\_getObjectsByType().

Referenced by ilLanguage(), and ilInitialisation\initLanguage().

346  {
347  include_once("./Services/Object/classes/class.ilObject.php");
348  $langlist = ilObject::_getObjectsByType("lng");
349 
350  foreach ($langlist as $lang)
351  {
352  if (substr($lang["desc"], 0, 9) == "installed")
353  {
354  $languages[] = $lang["title"];
355  }
356 
357  }
358 
359  return $languages ? $languages : array();
360  }
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstalledLocalLanguages()

ilLanguage::getInstalledLocalLanguages ( )

get already installed local languages (in db)

Returns
array array with inforamtion about each installed language

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

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

359  {
360  global $ilDB;
361 
362  $arr = array();
363 
364  $query = "SELECT * FROM object_data ".
365  "WHERE type = ".$ilDB->quote("lng", "text")." ".
366  "AND description = ".$ilDB->quote('installed_local', "text");
367  $r = $ilDB->query($query);
368 
369  while ($row = $ilDB->fetchObject($r))
370  {
371  $arr[] = $row->title;
372  }
373 
374  return $arr;
375  }
global $ilDB
$r

◆ getLangKey()

ilLanguage::getLangKey ( )

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

References $lang_key.

197  {
198  return $this->lang_key;
199  }

◆ getLanguages()

ilLanguage::getLanguages ( )

get all setup languages in the system

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

Returns
array langs

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

References $d, and $lang_key.

Referenced by getInstallableLanguages().

190  {
191  $d = dir($this->lang_path);
192  $tmpPath = getcwd();
193  chdir ($this->lang_path);
194 
195  // get available setup-files
196  while ($entry = $d->read())
197  {
198  if (is_file($entry) && (ereg ("(^setup_.{2}\.lang$)", $entry)))
199  {
200  $lang_key = substr($entry,6,2);
201  $languages[] = $lang_key;
202  }
203  }
204 
205  chdir($tmpPath);
206 
207  return $languages;
208  }
+ 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 541 of file class.ilLanguage.php.

References $ilDB, $result, $row, and DB_FETCHMODE_ASSOC.

Referenced by insertLanguage().

542  {
543  $ilDB = $this->db;
544 
545  if ($a_min_date == "")
546  {
547  $a_min_date = "1980-01-01 00:00:00";
548  }
549  if ($a_max_date == "")
550  {
551  $a_max_date = "2200-01-01 00:00:00";
552  }
553 
554  $q = sprintf("SELECT * FROM lng_data WHERE lang_key = %s ".
555  "AND local_change >= %s AND local_change <= %s",
556  $ilDB->quote($a_lang_key, "text"), $ilDB->quote($a_min_date, "timestamp"),
557  $ilDB->quote($a_max_date, "timestamp"));
558  $result = $ilDB->query($q);
559 
560  $changes = array();
561  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
562  {
563  $changes[$row["module"]][$row["identifier"]] = $row["value"];
564  }
565  return $changes;
566  }
$result
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
global $ilDB
+ 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 764 of file class.ilLanguage.php.

References $d, and $lang_key.

765  {
766  $local_langs = array();
767  if (is_dir($this->cust_lang_path))
768  {
769  $d = dir($this->cust_lang_path);
770  $tmpPath = getcwd();
771  chdir ($this->cust_lang_path);
772 
773  // get available .lang.local files
774  while ($entry = $d->read())
775  {
776  if (is_file($entry) && (ereg ("(^ilias_.{2}\.lang.local$)", $entry)))
777  {
778  $lang_key = substr($entry,6,2);
779  $local_langs[] = $lang_key;
780  }
781  }
782 
783  chdir($tmpPath);
784  }
785 
786  return $local_langs;
787  }

◆ getUsedModules()

ilLanguage::getUsedModules ( )

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

414  {
415  asort(self::$used_modules);
416  return self::$used_modules;
417  }

◆ getUsedTopics()

ilLanguage::getUsedTopics ( )

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

408  {
409  asort(self::$used_topics);
410  return self::$used_topics;
411  }

◆ getUserLanguage()

ilLanguage::getUserLanguage ( )

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

References $lang_user.

420  {
421  return $this->lang_user;
422  }

◆ ilLanguage() [1/2]

ilLanguage::ilLanguage (   $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. 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.

References $row, $txt, and ILIAS_ABSOLUTE_PATH.

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  {
112  foreach ($txt as $row)
113  {
114  if ($row[0] != "#")
115  {
116  $a = explode($this->separator,trim($row));
117  $this->text[trim($a[0])] = trim($a[1]);
118  }
119  }
120  }
121 
122  // set lang file...
123  $txt = file($this->lang_path."/setup_".$this->lang_key.".lang");
124 
125  // ...and load langdata
126  if (is_array($txt))
127  {
128  foreach ($txt as $row)
129  {
130  if ($row[0] != "#")
131  {
132  $a = explode($this->separator,trim($row));
133  $this->text[trim($a[0])] = trim($a[1]);
134  }
135  }
136 
137  return true;
138  }
139 
140  return false;
141  }
const ILIAS_ABSOLUTE_PATH
$txt
Definition: error.php:10

◆ ilLanguage() [2/2]

ilLanguage::ilLanguage (   $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.

public

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

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

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

140  {
142 
143  $this->ilias = $ilias;
144 
145  if (!isset($log))
146  {
147  if (is_object($ilias))
148  {
149  require_once "./Services/Logging/classes/class.ilLog.php";
150  $this->log = new ilLog(ILIAS_LOG_DIR,ILIAS_LOG_FILE,$ilias->getClientId(),ILIAS_LOG_ENABLED);
151  }
152  }
153  else
154  {
155  $this->log =& $log;
156  }
157 
158  $this->lang_key = $a_lang_key;
159 
160  $this->text = array();
161  $this->loaded_modules = array();
162  //$this->lang_path = ILIAS_ABSOLUTE_PATH.substr($this->ilias->ini->readVariable("language","path"),1);
163 
164  // if no directory was found fall back to default lang dir
165  //if (!is_dir($this->lang_path))
166  //{
167  $this->lang_path = ILIAS_ABSOLUTE_PATH."/lang";
168  //}
169  $this->cust_lang_path = ILIAS_ABSOLUTE_PATH."/Customizing/global/lang";
170 
171  $this->lang_default = $ilIliasIniFile->readVariable("language","default");
172  if (is_object($ilSetting) && $ilSetting->get("language") != "")
173  {
174  $this->lang_default = $ilSetting->get("language");
175  }
176  $this->lang_user = $ilUser->prefs["language"];
177 
178  $langs = $this->getInstalledLanguages();
179 
180  if (!in_array($this->lang_key,$langs))
181  {
182  $this->lang_key = $this->lang_default;
183  }
184 
185  require_once('./Services/Language/classes/class.ilCachedLanguage.php');
186  $this->global_cache = ilCachedLanguage::getInstance($this->lang_key);
187  if ($this->global_cache->isActive()) {
188  $this->cached_modules = $this->global_cache->getTranslations();
189  }
190 
191  $this->loadLanguageModule("common");
192 
193  return true;
194  }
logging
Definition: class.ilLog.php:18
const ILIAS_ABSOLUTE_PATH
global $ilIliasIniFile
redirection script todo: (a better solution should control the processing via a xml file) ...
global $ilUser
Definition: imgupload.php:15
global $ilSetting
Definition: privfeed.php:40
+ Here is the call graph for this function:

◆ 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 577 of file class.ilLanguage.php.

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

Referenced by installLanguages().

578  {
579  $ilDB =& $this->db;
580 
581  $lang_array = array();
582 
583  if (!empty($scope))
584  {
585  if ($scope == 'global')
586  {
587  $scope = '';
588  }
589  else
590  {
591  $scopeExtension = '.' . $scope;
592  }
593  }
594 
596  if ($scope == "local")
597  {
598  $path = $this->cust_lang_path;
599  }
600 
601  $tmpPath = getcwd();
602  chdir($path);
603 
604  $lang_file = "ilias_" . $lang_key . ".lang" . $scopeExtension;
605 
606  if ($lang_file)
607  {
608  // initialize the array for updating lng_modules below
609  $lang_array = array();
610  $lang_array["common"] = array();
611 
612  // remove header first
613  if ($content = $this->cut_header(file($lang_file)))
614  {
615  // get the local changes from the database
616  if (empty($scope))
617  {
618  $local_changes = $this->getLocalChanges($lang_key);
619  }
620  else if ($scope == 'local')
621  {
622  $change_date = date("Y-m-d H:i:s",time());
623  $min_date = date("Y-m-d H:i:s", filemtime($lang_file));
624  $local_changes = $this->getLocalChanges($lang_key, $min_date);
625  }
626 
627  foreach ($content as $key => $val)
628  {
629  $separated = explode($this->separator,trim($val));
630 
631  //get position of the comment_separator
632  $pos = strpos($separated[2], $this->comment_separator);
633 
634  if ($pos !== false)
635  {
636  //cut comment of
637  $separated[2] = substr($separated[2] , 0 , $pos);
638  }
639 
640  // check if the value has a local change
641  $local_value = $local_changes[$separated[0]][$separated[1]];
642 
643  if (empty($scope))
644  {
645  if ($local_value != "" and $local_value != $separated[2])
646  {
647  // keep the locally changed value
648  $lang_array[$separated[0]][$separated[1]] = $local_value;
649  }
650  else
651  {
652  // insert a new value if no local value exists
653  // reset local_change if the values are equal
654  ilLanguage::replaceLangEntry($separated[0], $separated[1],
655  $lang_key, $separated[2]);
656 
657  $lang_array[$separated[0]][$separated[1]] = $separated[2];
658  }
659  }
660  else if ($scope == 'local')
661  {
662  if ($local_value != "")
663  {
664  // keep a locally changed value that is newer than the local file
665  $lang_array[$separated[0]][$separated[1]] = $local_value;
666  }
667  else
668  {
669  // UPDATE because the global values have already been INSERTed
670  ilLanguage::updateLangEntry($separated[0], $separated[1],
671  $lang_key, $separated[2], $change_date);
672  $lang_array[$separated[0]][$separated[1]] = $separated[2];
673  }
674  }
675  }
676  }
677 
678  foreach($lang_array as $module => $lang_arr)
679  {
680  if ($scope == "local")
681  {
682  $q = "SELECT * FROM lng_modules WHERE ".
683  " lang_key = ".$ilDB->quote($this->key, "text").
684  " AND module = ".$ilDB->quote($module, "text");
685  $set = $ilDB->query($q);
686  $row = $ilDB->fetchAssoc($set);
687  $arr2 = unserialize($row["lang_array"]);
688  if (is_array($arr2))
689  {
690  $lang_arr = array_merge($arr2, $lang_arr);
691  }
692  }
693  ilLanguage::replaceLangModule($lang_key, $module, $lang_arr);
694  }
695  }
696 
697  chdir($tmpPath);
698  }
static replaceLangModule($a_key, $a_module, $a_array)
Replace language module array.
static updateLangEntry($a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null)
Update lang entry.
cut_header($content)
Remove *.lang header information from &#39;$content&#39;.
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.
$path
Definition: index.php:22
global $ilDB
+ 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 216 of file class.ilLanguage.php.

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

217  {
218  global $ilDB;
219 
220  if (empty($a_lang_keys))
221  {
222  $a_lang_keys = array();
223  }
224 
225  if (empty($a_local_keys))
226  {
227  $a_local_keys = array();
228  }
229 
230  $err_lang = array();
231 
232  $db_langs = $this->getAvailableLanguages();
233 
234  foreach ($a_lang_keys as $lang_key)
235  {
236  if ($this->checkLanguage($lang_key))
237  {
238  $this->flushLanguage($lang_key, 'keep_local');
239  $this->insertLanguage($lang_key);
240 
241  if (in_array($lang_key, $a_local_keys))
242  {
243  if ($this->checkLanguage($lang_key, "local"))
244  {
245  $this->insertLanguage($lang_key, "local");
246  }
247  else
248  {
249  $err_lang[] = $lang_key;
250  }
251  }
252 
253  // register language first time install
254  if (!array_key_exists($lang_key,$db_langs))
255  {
256  if (in_array($lang_key, $a_local_keys))
257  {
258  $itype = 'installed_local';
259  }
260  else
261  {
262  $itype = 'installed';
263  }
264  $lid = $ilDB->nextId("object_data");
265  $query = "INSERT INTO object_data ".
266  "(obj_id,type,title,description,owner,create_date,last_update) ".
267  "VALUES ".
268  "(".
269  $ilDB->quote($lid, "integer").",".
270  $ilDB->quote("lng", "text").",".
271  $ilDB->quote($lang_key, "text").",".
272  $ilDB->quote($itype, "text").",".
273  $ilDB->quote('-1',"integer").",".
274  $ilDB->now().",".
275  $ilDB->now().
276  ")";
277  $this->db->manipulate($query);
278  }
279  }
280  else
281  {
282  $err_lang[] = $lang_key;
283  }
284  }
285 
286  foreach ($db_langs as $key => $val)
287  {
288  if (!in_array($key,$err_lang))
289  {
290  if (in_array($key,$a_lang_keys))
291  {
292  if (in_array($key, $a_local_keys))
293  {
294  $ld = 'installed_local';
295  }
296  else
297  {
298  $ld = 'installed';
299  }
300  $query = "UPDATE object_data SET " .
301  "description = ".$ilDB->quote($ld, "text").", " .
302  "last_update = ".$ilDB->now()." " .
303  "WHERE obj_id = ".$ilDB->quote($val["obj_id"], "integer")." " .
304  "AND type = ".$ilDB->quote("lng", "text");
305  $ilDB->manipulate($query);
306  }
307  else
308  {
309  $this->flushLanguage($key, "all");
310 
311  if (substr($val["status"], 0, 9) == "installed")
312  {
313  $query = "UPDATE object_data SET " .
314  "description = ".$ilDB->quote("not_installed", "text").", " .
315  "last_update = ".$ilDB->now()." " .
316  "WHERE obj_id = ".$ilDB->quote($val["obj_id"], "integer")." " .
317  "AND type = ".$ilDB->quote("lng", "text");
318  $ilDB->manipulate($query);
319  }
320  }
321  }
322  }
323 
324  return ($err_lang) ? $err_lang : true;
325  }
getAvailableLanguages()
get already registered languages (in db)
checkLanguage($a_lang_key, $scope='')
validate the logical structure of a lang-file
flushLanguage($a_lang_key, $a_mode='all')
remove language data from database
insertLanguage($lang_key, $scope='')
insert language data from file in database
global $ilDB
+ Here is the call graph for this function:

◆ loadLanguageModule() [1/2]

ilLanguage::loadLanguageModule (   $a_module)

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

References $ilDB, $lang_key, $lang_user, $r, $row, and DB_FETCHMODE_ASSOC.

Referenced by ilObjUserGUI\__sendProfileMail().

293  {
294  global $ilDB;
295 
296  if (in_array($a_module, $this->loaded_modules))
297  {
298  return;
299  }
300 
301  $this->loaded_modules[] = $a_module;
302 
303  // remember the used modules globally
304  self::$used_modules[$a_module] = $a_module;
305 
307 
308  if (empty($this->lang_key))
309  {
311  }
312 
313  if(is_array($this->cached_modules[$a_module])) {
314  $this->text = array_merge($this->text, $this->cached_modules[$a_module]);
315 
316  return;
317  }
318 
319 /*
320  $query = "SELECT identifier,value FROM lng_data " .
321  "WHERE lang_key = '" . $lang_key."' " .
322  "AND module = '$a_module'";
323  $r = $this->ilias->db->query($query);
324 
325  while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
326  {
327  $this->text[$row->identifier] = $row->value;
328  }
329 */
330 
331  $q = "SELECT * FROM lng_modules " .
332  "WHERE lang_key = ".$ilDB->quote($lang_key, "text")." AND module = ".
333  $ilDB->quote($a_module, "text");
334  $r = $ilDB->query($q);
335  $row = $r->fetchRow(DB_FETCHMODE_ASSOC);
336 
337  $new_text = unserialize($row["lang_array"]);
338  if (is_array($new_text))
339  {
340  $this->text = array_merge($this->text, $new_text);
341  }
342  }
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
global $ilDB
$r
+ Here is the caller graph for this function:

◆ loadLanguageModule() [2/2]

ilLanguage::loadLanguageModule ( )

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

Referenced by ilLanguage().

832  {
833  }
+ Here is the caller graph for this function:

◆ lookupId()

static ilLanguage::lookupId (   $a_lang_key)
static

Lookup obj_id of language ilDB $ilDB.

Parameters
string$a_lang_key
Returns
int

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

References $ilDB, $query, $res, $row, and DB_FETCHMODE_OBJECT.

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

391  {
392  global $ilDB;
393 
394  $query = 'SELECT obj_id FROM object_data '.' '.
395  'WHERE title = '.$ilDB->quote($a_lang_key, 'text').' '.
396  'AND type = '.$ilDB->quote('lng','text');
397 
398  $res = $ilDB->query($query);
399  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
400  {
401  return $row->obj_id;
402  }
403  return 0;
404  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
global $ilDB
+ 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 723 of file class.ilLanguage.php.

References $ilDB.

Referenced by insertLanguage().

725  {
726  global $ilDB;
727 
728  $ilDB->manipulate(sprintf("DELETE FROM lng_data WHERE module = %s AND ".
729  "identifier = %s AND lang_key = %s",
730  $ilDB->quote($a_module, "text"), $ilDB->quote($a_identifier, "text"),
731  $ilDB->quote($a_lang_key, "text")));
732 
733  // insert a new value if no local value exists
734  // reset local_change if the values are equal
735  $ilDB->manipulate(sprintf("INSERT INTO lng_data " .
736  "(module, identifier, lang_key, value, local_change) " .
737  "VALUES (%s,%s,%s,%s,%s)",
738  $ilDB->quote($a_module, "text"), $ilDB->quote($a_identifier, "text"),
739  $ilDB->quote($a_lang_key, "text"), $ilDB->quote($a_value, "text"),
740  $ilDB->quote($a_local_change, "timestamp")));
741  }
global $ilDB
+ 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 703 of file class.ilLanguage.php.

References $ilDB.

Referenced by insertLanguage().

704  {
705  global $ilDB;
706 
707  $ilDB->manipulate(sprintf("DELETE FROM lng_modules WHERE lang_key = %s AND module = %s",
708  $ilDB->quote($a_key, "text"), $ilDB->quote($a_module, "text")));
709  /*$ilDB->manipulate(sprintf("INSERT INTO lng_modules (lang_key, module, lang_array) VALUES ".
710  "(%s,%s,%s)", $ilDB->quote($a_key, "text"),
711  $ilDB->quote($a_module, "text"),
712  $ilDB->quote(serialize($a_array), "clob")));*/
713  $ilDB->insert("lng_modules", array(
714  "lang_key" => array("text", $a_key),
715  "module" => array("text", $a_module),
716  "lang_array" => array("clob", serialize($a_array))
717  ));
718  }
global $ilDB
+ Here is the caller graph for this function:

◆ setDbHandler()

ilLanguage::setDbHandler (   $a_db_handler)

set db handler object object db handler

Returns
boolean true on success

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

820  {
821  if (empty($a_db_handler) or !is_object($a_db_handler))
822  {
823  return false;
824  }
825 
826  $this->db =& $a_db_handler;
827 
828  return true;
829  }

◆ 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 public

Parameters
stringtopic
Returns
string text clear-text

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

References $log.

152  {
153  global $log;
154 
155  if (empty($a_topic))
156  {
157  return "";
158  }
159 
160  $translation = $this->text[$a_topic];
161 
162  //get position of the comment_separator
163  $pos = strpos($translation, $this->comment_separator);
164 
165  if ($pos !== false)
166  {
167  // remove comment
168  $translation = substr($translation,0,$pos);
169  }
170 
171  if ($translation == "")
172  {
173  $log->writeLanguageLog($a_topic,$this->lang_key);
174  return "-".$a_topic."-";
175  }
176  else
177  {
178  return $translation;
179  }
180  }

◆ 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

public

Parameters
stringtopic
Returns
string text clear-text

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

References _lookupEntry().

Referenced by assKprimChoice\getAnswerTypeSelectOptions(), ilObjTestDynamicQuestionSetConfig\getDepenciesBrokenMessage(), ilTestRandomQuestionSetConfig\getDepenciesBrokenMessage(), ilObjTestDynamicQuestionSetConfig\getDepenciesInVulnerableStateMessage(), assKprimChoice\getFalseOptionLabelTranslation(), ilAssQuestionHint\getHintIndexLabel(), assKprimChoice\getInstructionTextTranslation(), ilTestRandomQuestionSetSourcePoolDefinition\getPoolInfoLabel(), ilObjTest\getQuestionSetTypeTranslation(), ilObjTestDynamicQuestionSetConfig\getSourceQuestionPoolSummaryString(), assKprimChoice\getTrueOptionLabelTranslation(), assKprimChoice\getValidOptionLabelsTranslated(), ilTestToplistGUI\manageTabs(), and txtlng().

236  {
237  if (empty($a_topic))
238  {
239  return "";
240  }
241 
242  // remember the used topics
243  self::$used_topics[$a_topic] = $a_topic;
244 
245  $translation = "";
246  if (isset($this->text[$a_topic]))
247  {
248  $translation = $this->text[$a_topic];
249  }
250 
251  if ($translation == "" && $a_default_lang_fallback_mod != "")
252  {
253  // #13467 - try current language first (could be missing module)
254  if($this->lang_key != $this->lang_default)
255  {
256  $translation = ilLanguage::_lookupEntry($this->lang_key,
257  $a_default_lang_fallback_mod, $a_topic);
258  }
259  // try default language last
260  if($translation == "" || $translation == "-".$a_topic."-")
261  {
262  $translation = ilLanguage::_lookupEntry($this->lang_default,
263  $a_default_lang_fallback_mod, $a_topic);
264  }
265  }
266 
267 
268  if ($translation == "")
269  {
270  if (ILIAS_LOG_ENABLED && is_object($this->log))
271  {
272  $this->log->writeLanguageLog($a_topic,$this->lang_key);
273  }
274  return "-".$a_topic."-";
275  }
276  else
277  {
278  return $translation;
279  }
280  }
static _lookupEntry($a_lang_key, $a_mod, $a_id)
+ 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

public

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

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

References _lookupEntry(), and txt().

216  {
217  if (strcmp($a_language, $this->lang_key) == 0)
218  {
219  return $this->txt($a_topic);
220  }
221  else
222  {
223  return ilLanguage::_lookupEntry($a_language, $a_module, $a_topic);
224  }
225  }
static _lookupEntry($a_lang_key, $a_mod, $a_id)
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...
+ 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 746 of file class.ilLanguage.php.

References $ilDB.

Referenced by insertLanguage().

748  {
749  global $ilDB;
750 
751  $ilDB->manipulate(sprintf("UPDATE lng_data " .
752  "SET value = %s, local_change = %s ".
753  "WHERE module = %s AND identifier = %s AND lang_key = %s ",
754  $ilDB->quote($a_value, "text"), $ilDB->quote($a_local_change, "timestamp"),
755  $ilDB->quote($a_module, "text"), $ilDB->quote($a_identifier, "text"),
756  $ilDB->quote($a_lang_key, "text")));
757  }
global $ilDB
+ 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 ilLanguage().

◆ $lang_default

ilLanguage::$lang_default = "en"

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

Referenced by ilLanguage().

◆ $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().

◆ $loaded_modules

ilLanguage::$loaded_modules

Definition at line 111 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.

◆ $used_modules

ilLanguage::$used_modules = array()
staticprotected

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

◆ $used_topics

ilLanguage::$used_topics = array()
staticprotected

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


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