Public Member Functions | |
ilLanguage ($a_lang_key) | |
Constructor read the single-language file and put this in an array text. | |
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 | |
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 | |
loadLanguageModule ($a_module) | |
getInstalledLanguages () | |
_lookupEntry ($a_lang_key, $a_mod, $a_id) | |
ilLanguage ($a_lang_key) | |
Constructor read the single-language file and put this in an array text. | |
txt ($a_topic) | |
gets the text for a given topic | |
getLanguages () | |
get all setup languages in the system | |
installLanguages ($a_lang_keys, $a_local_keys) | |
install languages | |
getInstalledLanguages () | |
get already installed languages (in db) | |
getInstalledLocalLanguages () | |
get already installed local languages (in db) | |
getAvailableLanguages () | |
get already registered languages (in db) | |
checkLanguage ($a_lang_key, $scope= '') | |
validate the logical structure of a lang-file | |
cut_header ($content) | |
Remove *.lang header information from '$content'. | |
flushLanguages () | |
remove all languagee from database | |
insertLanguage ($lang_key, $scope= '') | |
insert language data from file in database | |
getLocalLanguages () | |
Searches for the existence of *.lang.local files. | |
getInstallableLanguages () | |
setDbHandler ($a_db_handler) | |
set db handler object object db handler | |
Data Fields | |
$ilias | |
$text = array() | |
$lang_default = "en" | |
$lang_user | |
$lang_path | |
$lang_key | |
$lang_name | |
$separator = "#:#" | |
$comment_separator = "###" | |
$loaded_modules |
Definition at line 47 of file class.ilLanguage.php.
ilLanguage::_lookupEntry | ( | $ | a_lang_key, | |
$ | a_mod, | |||
$ | a_id | |||
) |
Definition at line 319 of file class.ilLanguage.php.
Referenced by ilRegistrationGUI::displayForm(), ilAccountMail::replacePlaceholders(), ilMainMenuGUI::setTemplateVars(), ilStartUpGUI::showLogin(), ilPersonalProfileGUI::showProfile(), and ilStartUpGUI::showUserAgreement().
{ global $ilDB; $q = "SELECT * FROM lng_data WHERE". " module = ".$ilDB->quote($a_mod). " AND lang_key =".$ilDB->quote($a_lang_key). " AND identifier =".$ilDB->quote($a_id); $set = $ilDB->query($q); $rec = $set->fetchRow(DB_FETCHMODE_ASSOC); if ($rec["value"] != "") { return $rec["value"]; } return "-".$a_id."-"; }
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).
string | $a_lang_key international language key (2 digits) | |
string | $scope empty (global) or "local" |
Definition at line 397 of file class.ilLanguage.php.
References $key, and cut_header().
Referenced by installLanguages().
{ if (!empty($scope)) { if ($scope == 'global') { $scope = ''; } else { $scopeExtension = '.' . $scope; } } $tmpPath = getcwd(); chdir($this->lang_path); // compute lang-file name format $lang_file = "ilias_" . $a_lang_key . ".lang" . $scopeExtension; // file check if (!is_file($lang_file)) { chdir($tmpPath); return false; } // header check if (!$content = $this->cut_header(file($lang_file))) { chdir($tmpPath); return false; } // check (counting) elements of each lang-entry foreach ($content as $key => $val) { $separated = explode($this->separator, trim($val)); $num = count($separated); if ($num != 3) { chdir($tmpPath); return false; } } chdir($tmpPath); // no error occured return true; }
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.
string | $content expect an ILIAS lang-file |
Definition at line 460 of file class.ilLanguage.php.
References $key.
Referenced by checkLanguage(), and insertLanguage().
{ foreach ($content as $key => $val) { if (trim($val) == "<!-- language file start -->") { return array_slice($content,$key +1); } } return false; }
ilLanguage::flushLanguages | ( | ) |
remove all languagee from database
Definition at line 476 of file class.ilLanguage.php.
References $query.
Referenced by installLanguages().
ilLanguage::getAvailableLanguages | ( | ) |
get already registered languages (in db)
Definition at line 369 of file class.ilLanguage.php.
Referenced by installLanguages().
{ $arr = array(); $query = "SELECT * FROM object_data ". "WHERE type = 'lng'"; $r = $this->db->query($query); while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT)) { $arr[$row->title]["obj_id"] = $row->obj_id; $arr[$row->title]["status"] = $row->description; } return $arr; }
ilLanguage::getDefaultLanguage | ( | ) |
Definition at line 191 of file class.ilLanguage.php.
{
return $this->lang_default;
}
ilLanguage::getInstallableLanguages | ( | ) |
Definition at line 612 of file class.ilLanguage.php.
References $d, $lang_key, and getLanguages().
{ $setup_langs = $this->getLanguages(); $d = dir($this->lang_path); $tmpPath = getcwd(); chdir ($this->lang_path); // get available lang-files while ($entry = $d->read()) { if (is_file($entry) && (ereg ("(^ilias_.{2}\.lang$)", $entry))) { $lang_key = substr($entry,6,2); $languages1[] = $lang_key; } } //$languages = array_intersect($languages1,$setup_langs); chdir($tmpPath); return $languages1; }
ilLanguage::getInstalledLanguages | ( | ) |
get already installed languages (in db)
Definition at line 326 of file class.ilLanguage.php.
ilLanguage::getInstalledLanguages | ( | ) |
Definition at line 303 of file class.ilLanguage.php.
References $lang, and getObjectList().
Referenced by ilLanguage().
{ $langlist = getObjectList("lng"); foreach ($langlist as $lang) { if (substr($lang["desc"], 0, 9) == "installed") { $languages[] = $lang["title"]; } } return $languages; }
ilLanguage::getInstalledLocalLanguages | ( | ) |
get already installed local languages (in db)
Definition at line 348 of file class.ilLanguage.php.
ilLanguage::getLangKey | ( | ) |
Definition at line 186 of file class.ilLanguage.php.
{
return $this->lang_key;
}
ilLanguage::getLanguages | ( | ) |
get all setup languages in the system
the functions looks for setup*.lang-files in the languagedirectory public
Definition at line 190 of file class.ilLanguage.php.
Referenced by getInstallableLanguages().
{ $d = dir($this->lang_path); $tmpPath = getcwd(); chdir ($this->lang_path); // get available setup-files while ($entry = $d->read()) { if (is_file($entry) && (ereg ("(^setup_.{2}\.lang$)", $entry))) { $lang_key = substr($entry,6,2); $languages[] = $lang_key; } } chdir($tmpPath); return $languages; }
ilLanguage::getLocalLanguages | ( | ) |
Searches for the existence of *.lang.local files.
return $local_langs array of language keys
Definition at line 590 of file class.ilLanguage.php.
{ $local_langs = array(); $d = dir($this->lang_path); $tmpPath = getcwd(); chdir ($this->lang_path); // get available .lang.local files while ($entry = $d->read()) { if (is_file($entry) && (ereg ("(^ilias_.{2}\.lang.local$)", $entry))) { $lang_key = substr($entry,6,2); $local_langs[] = $lang_key; } } chdir($tmpPath); return $local_langs; }
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
string | languagecode (two characters), e.g. "de", "en", "in" |
Definition at line 144 of file class.ilLanguage.php.
References $ilias, $log, getInstalledLanguages(), and loadLanguageModule().
{ global $ilias,$log; $this->ilias =& $ilias; if (!isset($log)) { $this->log = new ilLog(ILIAS_LOG_DIR,ILIAS_LOG_FILE,$ilias->getClientId(),ILIAS_LOG_ENABLED); } else { $this->log =& $log; } $this->lang_key = $a_lang_key; $this->text = array(); $this->loaded_modules = array(); $this->lang_path = ILIAS_ABSOLUTE_PATH.substr($this->ilias->ini->readVariable("language","path"),1); // if no directory was found fall back to default lang dir if (!is_dir($this->lang_path)) { $this->lang_path = ILIAS_ABSOLUTE_PATH."/lang"; } $this->lang_default = $this->ilias->ini->readVariable("language","default"); $this->lang_user = $this->ilias->account->prefs["language"]; $langs = $this->getInstalledLanguages(); if (!in_array($this->lang_key,$langs)) { $this->lang_key = $this->lang_default; } $this->loadLanguageModule("common"); return true; }
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
string | languagecode (two characters), e.g. "de", "en", "in" |
Definition at line 101 of file class.ilLanguage.php.
References $row.
{ $this->lang_key = ($a_lang_key) ? $a_lang_key : $this->lang_default; //$_GET["lang"] = $this->lang_key; // only for downward compability (old setup) $this->lang_path = ILIAS_ABSOLUTE_PATH."/lang"; // set lang file... $txt = file($this->lang_path."/setup_lang_sel_multi.lang"); // ...and load langdata if (is_array($txt)) { foreach ($txt as $row) { if ($row[0] != "#") { $a = explode($this->separator,trim($row)); $this->text[trim($a[0])] = trim($a[1]); } } } // set lang file... $txt = file($this->lang_path."/setup_".$this->lang_key.".lang"); // ...and load langdata if (is_array($txt)) { foreach ($txt as $row) { if ($row[0] != "#") { $a = explode($this->separator,trim($row)); $this->text[trim($a[0])] = trim($a[1]); } } return true; } return false; }
ilLanguage::insertLanguage | ( | $ | lang_key, | |
$ | scope = '' | |||
) |
insert language data from file in database
string | $lang_key international language key (2 digits) | |
string | $scope empty (global) or "local" |
Definition at line 490 of file class.ilLanguage.php.
References $key, $lang_key, $pos, $q, $query, $row, $set, and cut_header().
Referenced by installLanguages().
{ $ilDB =& $this->db; $lang_array = array(); if (!empty($scope)) { if ($scope == 'global') { $scope = ''; } else { $scopeExtension = '.' . $scope; } } $tmpPath = getcwd(); chdir($this->lang_path); $lang_file = "ilias_" . $lang_key . ".lang" . $scopeExtension; if ($lang_file) { // remove header first if ($content = $this->cut_header(file($lang_file))) { foreach ($content as $key => $val) { $separated = explode($this->separator,trim($val)); //get position of the comment_separator $pos = strpos($separated[2], $this->comment_separator); if ($pos !== false) { //cut comment of $separated[2] = substr($separated[2] , 0 , $pos); } if (empty($scope)) { $query = "INSERT INTO lng_data ". "(module,identifier,lang_key,value) ". "VALUES ". "('" . $separated[0] . "','" . $separated[1] . "','" . $lang_key . "','" . addslashes($separated[2]) . "')"; $lang_array[$separated[0]][$separated[1]] = $separated[2]; } else if ($scope == 'local') { $query = "UPDATE lng_data SET ". "module = '" . $separated[0] . "', " . "identifier = '" . $separated[1] . "', " . "lang_key = '" . $lang_key . "', " . "value = '" . addslashes($separated[2]) . "' " . "WHERE module = '" . $separated[0] . "' " . "AND identifier = '" . $separated[1] . "' " . "AND lang_key = '" . $lang_key . "'"; $lang_array[$separated[0]][$separated[1]] = $separated[2]; } $this->db->query($query); } } // insert module data $lang_array[$separated[0]][$separated[1]] = $separated[2]; foreach($lang_array as $module => $lang_arr) { if ($scope == "local") { $q = "SELECT * FROM lng_modules WHERE ". " lang_key = ".$ilDB->quote($this->key). " AND module = ".$ilDB->quote($module); $set = $ilDB->query($q); $row = $set->fetchRow(DB_FETCHMODE_ASSOC); $arr2 = unserialize($row["lang_array"]); if (is_array($arr2)) { $lang_arr = array_merge($arr2, $lang_arr); } } $query = "REPLACE INTO lng_modules (lang_key, module, lang_array) VALUES ". "(".$ilDB->quote($lang_key).", " . " ".$ilDB->quote($module).", " . " ".$ilDB->quote(serialize($lang_arr)).") "; $ilDB->query($query); } } chdir($tmpPath); }
ilLanguage::installLanguages | ( | $ | a_lang_keys, | |
$ | a_local_keys | |||
) |
install languages
array | array with lang_keys of languages to install |
Definition at line 217 of file class.ilLanguage.php.
References $key, $lang_key, $query, checkLanguage(), flushLanguages(), getAvailableLanguages(), and insertLanguage().
{ if (empty($a_lang_keys)) { $a_lang_keys = array(); } if (empty($a_local_keys)) { $a_local_keys = array(); } $err_lang = array(); $this->flushLanguages(); $db_langs = $this->getAvailableLanguages(); foreach ($a_lang_keys as $lang_key) { if ($this->checkLanguage($lang_key)) { $this->insertLanguage($lang_key); if (in_array($lang_key, $a_local_keys)) { if ($this->checkLanguage($lang_key, "local")) { $this->insertLanguage($lang_key, "local"); } else { $err_lang[] = $lang_key; } } // register language first time install if (!array_key_exists($lang_key,$db_langs)) { if (in_array($lang_key, $a_local_keys)) { $query = "INSERT INTO object_data ". "(type,title,description,owner,create_date,last_update) ". "VALUES ". "('lng','".$lang_key."','installed_local','-1',now(),now())"; } else { $query = "INSERT INTO object_data ". "(type,title,description,owner,create_date,last_update) ". "VALUES ". "('lng','".$lang_key."','installed','-1',now(),now())"; } $this->db->query($query); } } else { $err_lang[] = $lang_key; } } foreach ($db_langs as $key => $val) { if (!in_array($key,$err_lang)) { if (in_array($key,$a_lang_keys)) { if (in_array($key, $a_local_keys)) { $query = "UPDATE object_data SET " . "description = 'installed_local', " . "last_update = now() " . "WHERE obj_id='".$val["obj_id"]."' " . "AND type='lng'"; } else { $query = "UPDATE object_data SET " . "description = 'installed', " . "last_update = now() " . "WHERE obj_id='".$val["obj_id"]."' " . "AND type='lng'"; } $this->db->query($query); } else { if (substr($val["status"], 0, 9) == "installed") { $query = "UPDATE object_data SET " . "description = 'not_installed', " . "last_update = now() " . "WHERE obj_id='" . $val["obj_id"] . "' " . "AND type='lng'"; $this->db->query($query); } } } } return ($err_lang) ? $err_lang : true; }
ilLanguage::loadLanguageModule | ( | $ | a_module | ) |
Definition at line 262 of file class.ilLanguage.php.
References $lang_key, $query, and $row.
Referenced by ilLanguage().
{ if (in_array($a_module, $this->loaded_modules)) { return; } $this->loaded_modules[] = $a_module; $lang_key = $this->lang_key; if (empty($this->lang_key)) { $lang_key = $this->lang_user; } /* $query = "SELECT identifier,value FROM lng_data " . "WHERE lang_key = '" . $lang_key."' " . "AND module = '$a_module'"; $r = $this->ilias->db->query($query); while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT)) { $this->text[$row->identifier] = $row->value; } */ $query = "SELECT * FROM lng_modules " . "WHERE lang_key = '".$lang_key."' " . "AND module = '$a_module'"; $r = $this->ilias->db->query($query); $row = $r->fetchRow(DB_FETCHMODE_ASSOC); $new_text = unserialize($row["lang_array"]); if (is_array($new_text)) { $this->text = array_merge($this->text, $new_text); } }
ilLanguage::setDbHandler | ( | $ | a_db_handler | ) |
set db handler object object db handler
Definition at line 642 of file class.ilLanguage.php.
{ if (empty($a_db_handler) or !is_object($a_db_handler)) { return false; } $this->db =& $a_db_handler; return true; }
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
string | topic |
Definition at line 152 of file class.ilLanguage.php.
{ global $log; if (empty($a_topic)) { return ""; } $translation = $this->text[$a_topic]; //get position of the comment_separator $pos = strpos($translation, $this->comment_separator); if ($pos !== false) { // remove comment $translation = substr($translation,0,$pos); } if ($translation == "") { $log->writeLanguageLog($a_topic,$this->lang_key); return "-".$a_topic."-"; } else { return $translation; } }
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
string | topic |
Definition at line 239 of file class.ilLanguage.php.
Referenced by txtlng().
{ if (empty($a_topic)) { return ""; } $translation = $this->text[$a_topic]; if ($translation == "") { if (ILIAS_LOG_ENABLED) { $this->log->writeLanguageLog($a_topic,$this->lang_key); } return "-".$a_topic."-"; } else { return $translation; } }
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
string | topic | |
string | $a_language The language of the output string |
Definition at line 205 of file class.ilLanguage.php.
References $query, $row, and txt().
{ if (strcmp($a_language, $this->lang_key) == 0) { return $this->txt($a_topic); } else { $query = sprintf("SELECT value FROM lng_data WHERE lang_key = %s AND module = %s AND identifier = %s", $this->ilias->db->quote($a_language . ""), $this->ilias->db->quote($a_module . ""), $this->ilias->db->quote($a_topic . "") ); $r = $this->ilias->db->query($query); if ($row = $r->fetchRow(DB_FETCHMODE_OBJECT)) { return $row->value; } else { return "-".$a_topic."-"; } } }
ilLanguage::$comment_separator = "###" |
Definition at line 124 of file class.ilLanguage.php.
ilLanguage::$ilias |
Definition at line 55 of file class.ilLanguage.php.
Referenced by ilLanguage().
ilLanguage::$lang_default = "en" |
Definition at line 72 of file class.ilLanguage.php.
ilLanguage::$lang_key |
Definition at line 100 of file class.ilLanguage.php.
Referenced by getInstallableLanguages(), getLanguages(), getLocalLanguages(), insertLanguage(), installLanguages(), and loadLanguageModule().
ilLanguage::$lang_name |
Definition at line 108 of file class.ilLanguage.php.
ilLanguage::$lang_path |
Definition at line 92 of file class.ilLanguage.php.
ilLanguage::$lang_user |
Definition at line 82 of file class.ilLanguage.php.
ilLanguage::$loaded_modules |
Definition at line 132 of file class.ilLanguage.php.
ilLanguage::$separator = "#:#" |
Definition at line 116 of file class.ilLanguage.php.
ilLanguage::$text = array() |
Definition at line 63 of file class.ilLanguage.php.