ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
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 ()
 
 _lookupEntry ($a_lang_key, $a_mod, $a_id)
 
 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 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
 

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.

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  }
+ Here is the caller graph for this function:

◆ _lookupEntry()

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

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

Referenced by ilLinkChecker\__txt(), ilAccountRegistrationGUI\executeCommand(), ilStartUpGUI\getAcceptance(), ilPersonalSettingsGUI\initGeneralSettingsForm(), ilAccountMail\replacePlaceholders(), ilStartUpGUI\showLanguageSelection(), ilUserCronCheckAccounts\txt(), txt(), and txtlng().

342  {
343  global $ilDB;
344 
345  $set = $ilDB->query($q = sprintf("SELECT * FROM lng_data WHERE module = %s ".
346  "AND lang_key = %s AND identifier = %s",
347  $ilDB->quote((string) $a_mod, "text"), $ilDB->quote((string) $a_lang_key, "text"),
348  $ilDB->quote((string) $a_id, "text")));
349  $rec = $ilDB->fetchAssoc($set);
350 
351  if ($rec["value"] != "")
352  {
353  // remember the used topics
354  $this->used_topics[$a_id] = $a_id;
355  $this->used_modules[$a_mod] = $a_mod;
356 
357  return $rec["value"];
358  }
359 
360  return "-".$a_id."-";
361  }
+ 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 272 of file class.ilLanguage.php.

273  {
274  return isset($this->text[$a_topic]);
275  }

◆ 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 _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.
+ 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 $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  }
$r
+ Here is the caller graph for this function:

◆ getDefaultLanguage()

ilLanguage::getDefaultLanguage ( )

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

187  {
188  return $this->lang_default ? $this->lang_default : 'en';
189  }

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

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

References $lang, and ilObject\_getObjectsByType().

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

325  {
326  include_once("./Services/Object/classes/class.ilObject.php");
327  $langlist = ilObject::_getObjectsByType("lng");
328 
329  foreach ($langlist as $lang)
330  {
331  if (substr($lang["desc"], 0, 9) == "installed")
332  {
333  $languages[] = $lang["title"];
334  }
335 
336  }
337 
338  return $languages ? $languages : array();
339  }
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:

◆ getInstalledLanguages() [2/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 $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  }
$r

◆ 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 $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  }
$r

◆ getLangKey()

ilLanguage::getLangKey ( )

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

References $lang_key.

182  {
183  return $this->lang_key;
184  }

◆ 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 $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
+ 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 399 of file class.ilLanguage.php.

400  {
401  if (is_array($this->used_modules))
402  {
403  asort($this->used_modules);
404  return $this->used_modules;
405  }
406  else
407  {
408  return array();
409  }
410  }

◆ getUsedTopics()

ilLanguage::getUsedTopics ( )

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

387  {
388  if (is_array($this->used_topics))
389  {
390  asort($this->used_topics);
391  return $this->used_topics;
392  }
393  else
394  {
395  return array();
396  }
397  }

◆ getUserLanguage()

ilLanguage::getUserLanguage ( )

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

References $lang_user.

413  {
414  return $this->lang_user;
415  }

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

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

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

124  {
126 
127  // store used modules and topics in a global variable
128  // ($lng seems to be initialized more than once)
129  global $ilias_lang_used_topics;
130  global $ilias_lang_used_modules;
131  $this->used_topics =& $ilias_lang_used_topics;
132  $this->used_modules =& $ilias_lang_used_modules;
133 
134  $this->ilias =& $ilias;
135 
136  if (!isset($log))
137  {
138  if (is_object($ilias))
139  {
140  require_once "./Services/Logging/classes/class.ilLog.php";
141  $this->log = new ilLog(ILIAS_LOG_DIR,ILIAS_LOG_FILE,$ilias->getClientId(),ILIAS_LOG_ENABLED);
142  }
143  }
144  else
145  {
146  $this->log =& $log;
147  }
148 
149  $this->lang_key = $a_lang_key;
150 
151  $this->text = array();
152  $this->loaded_modules = array();
153  //$this->lang_path = ILIAS_ABSOLUTE_PATH.substr($this->ilias->ini->readVariable("language","path"),1);
154 
155  // if no directory was found fall back to default lang dir
156  //if (!is_dir($this->lang_path))
157  //{
158  $this->lang_path = ILIAS_ABSOLUTE_PATH."/lang";
159  //}
160  $this->cust_lang_path = ILIAS_ABSOLUTE_PATH."/Customizing/global/lang";
161 
162  $this->lang_default = $ilIliasIniFile->readVariable("language","default");
163  if (is_object($ilSetting) && $ilSetting->get("language") != "")
164  {
165  $this->lang_default = $ilSetting->get("language");
166  }
167  $this->lang_user = $ilUser->prefs["language"];
168 
169  $langs = $this->getInstalledLanguages();
170 
171  if (!in_array($this->lang_key,$langs))
172  {
173  $this->lang_key = $this->lang_default;
174  }
175 
176  $this->loadLanguageModule("common");
177 
178  return true;
179  }
logging
Definition: class.ilLog.php:18
const ILIAS_ABSOLUTE_PATH
redirection script todo: (a better solution should control the processing via a xml file) ...
global $ilIliasIniFile
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 $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
+ 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 $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
+ Here is the call graph for this function:

◆ loadLanguageModule() [1/2]

ilLanguage::loadLanguageModule (   $a_module)

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

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

Referenced by ilObjUserGUI\__sendProfileMail().

278  {
279  global $ilDB;
280 
281  if (in_array($a_module, $this->loaded_modules))
282  {
283  return;
284  }
285 
286  $this->loaded_modules[] = $a_module;
287 
288  // remember the used modules globally
289  $this->used_modules[$a_module] = $a_module;
290 
292 
293  if (empty($this->lang_key))
294  {
296  }
297 
298 /*
299  $query = "SELECT identifier,value FROM lng_data " .
300  "WHERE lang_key = '" . $lang_key."' " .
301  "AND module = '$a_module'";
302  $r = $this->ilias->db->query($query);
303 
304  while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
305  {
306  $this->text[$row->identifier] = $row->value;
307  }
308 */
309 
310  $q = "SELECT * FROM lng_modules " .
311  "WHERE lang_key = ".$ilDB->quote($lang_key, "text")." AND module = ".
312  $ilDB->quote($a_module, "text");
313  $r = $ilDB->query($q);
314  $row = $r->fetchRow(DB_FETCHMODE_ASSOC);
315 
316  $new_text = unserialize($row["lang_array"]);
317  if (is_array($new_text))
318  {
319  $this->text = array_merge($this->text, $new_text);
320  }
321  }
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
$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 369 of file class.ilLanguage.php.

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

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

370  {
371  global $ilDB;
372 
373  $query = 'SELECT obj_id FROM object_data '.' '.
374  'WHERE title = '.$ilDB->quote($a_lang_key, 'text').' '.
375  'AND type = '.$ilDB->quote('lng','text');
376 
377  $res = $ilDB->query($query);
378  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
379  {
380  return $row->obj_id;
381  }
382  return 0;
383  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
+ 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.

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  }
+ 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.

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  }
+ 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 220 of file class.ilLanguage.php.

References _lookupEntry().

Referenced by ilObjTestDynamicQuestionSetConfig\getDepenciesBrokenMessage(), ilTestRandomQuestionSetConfig\getDepenciesBrokenMessage(), ilObjTestDynamicQuestionSetConfig\getDepenciesInVulnerableStateMessage(), ilAssQuestionHint\getHintIndexLabel(), ilTestRandomQuestionSetSourcePoolDefinition\getPoolInfoLabel(), ilObjTest\getQuestionSetTypeTranslation(), ilObjTestDynamicQuestionSetConfig\getSourceQuestionPoolSummaryString(), and txtlng().

221  {
222  if (empty($a_topic))
223  {
224  return "";
225  }
226 
227  // remember the used topics
228  $this->used_topics[$a_topic] = $a_topic;
229 
230  $translation = "";
231  if (isset($this->text[$a_topic]))
232  {
233  $translation = $this->text[$a_topic];
234  }
235 
236  if ($translation == "" && $a_default_lang_fallback_mod != "")
237  {
238  // #13467 - try current language first (could be missing module)
239  if($this->lang_key != $this->lang_default)
240  {
241  $translation = ilLanguage::_lookupEntry($this->lang_key,
242  $a_default_lang_fallback_mod, $a_topic);
243  }
244  // try default language last
245  if($translation == "" || $translation == "-".$a_topic."-")
246  {
247  $translation = ilLanguage::_lookupEntry($this->lang_default,
248  $a_default_lang_fallback_mod, $a_topic);
249  }
250  }
251 
252 
253  if ($translation == "")
254  {
255  if (ILIAS_LOG_ENABLED && is_object($this->log))
256  {
257  $this->log->writeLanguageLog($a_topic,$this->lang_key);
258  }
259  return "-".$a_topic."-";
260  }
261  else
262  {
263  return $translation;
264  }
265  }
_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 200 of file class.ilLanguage.php.

References _lookupEntry(), and txt().

201  {
202  if (strcmp($a_language, $this->lang_key) == 0)
203  {
204  return $this->txt($a_topic);
205  }
206  else
207  {
208  return ilLanguage::_lookupEntry($a_language, $a_module, $a_topic);
209  }
210  }
_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.

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  }
+ Here is the caller graph for this function:

Field Documentation

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


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