105        $this->lang_key = ($a_lang_key) ? $a_lang_key : $this->lang_default;
 
  107        $il_absolute_path = realpath(dirname(__FILE__) . 
'/../../../../');
 
  108        $this->lang_path = $il_absolute_path . 
"/lang";
 
  109        $this->cust_lang_path = $il_absolute_path . 
"/Customizing/global/lang";
 
  112        $txt = file($this->lang_path . 
"/setup_lang_sel_multi.lang");
 
  115        if (is_array(
$txt)) {
 
  116            foreach (
$txt as $row) {
 
  117                if ($row[0] != 
"#") {
 
  118                    $a = explode($this->separator, trim($row));
 
  119                    if (count(
$a) == 2) {
 
  120                        $this->text[trim(
$a[0])] = trim(
$a[1]);
 
  127        $txt = file($this->lang_path . 
"/setup_" . $this->lang_key . 
".lang");
 
  130        if (is_array(
$txt)) {
 
  131            foreach (
$txt as $row) {
 
  132                if ($row[0] != 
"#") {
 
  133                    $a = explode($this->separator, trim($row));
 
  134                    if (count(
$a) == 2) {
 
  135                        $this->text[trim(
$a[0])] = trim(
$a[1]);
 
  154    public function txt($a_topic, $a_default_lang_fallback_mod = 
'')
 
  158        if (empty($a_topic)) {
 
  162        $translation = $this->text[$a_topic];
 
  165        $pos = strpos($translation, $this->comment_separator);
 
  167        if ($pos !== 
false) {
 
  169            $translation = substr($translation, 0, $pos);
 
  172        if ($translation == 
"") {
 
  173            $log->writeLanguageLog($a_topic, $this->lang_key);
 
  174            return "-" . $a_topic . 
"-";
 
  189        $d = dir($this->lang_path);
 
  191        chdir($this->lang_path);
 
  194        while ($entry = 
$d->read()) {
 
  195            if (is_file($entry) && (preg_match(
'/(^setup_.{2}\.lang$)/', $entry))) {
 
  216        if (empty($a_lang_keys)) {
 
  217            $a_lang_keys = array();
 
  220        if (empty($a_local_keys)) {
 
  221            $a_local_keys = array();
 
  233                if (in_array(
$lang_key, $a_local_keys) && is_dir($this->cust_lang_path)) {
 
  242                if (!array_key_exists(
$lang_key, $db_langs)) {
 
  243                    if (in_array(
$lang_key, $a_local_keys)) {
 
  244                        $itype = 
'installed_local';
 
  246                        $itype = 
'installed';
 
  248                    $lid = 
$ilDB->nextId(
"object_data");
 
  249                    $query = 
"INSERT INTO object_data " .
 
  250                            "(obj_id,type,title,description,owner,create_date,last_update) " .
 
  253                            $ilDB->quote($lid, 
"integer") . 
"," .
 
  254                            $ilDB->quote(
"lng", 
"text") . 
"," .
 
  256                            $ilDB->quote($itype, 
"text") . 
"," .
 
  257                            $ilDB->quote(
'-1', 
"integer") . 
"," .
 
  261                    $this->db->manipulate(
$query);
 
  268        foreach ($db_langs as $key => $val) {
 
  269            if (!in_array($key, $err_lang)) {
 
  270                if (in_array($key, $a_lang_keys)) {
 
  271                    if (in_array($key, $a_local_keys)) {
 
  272                        $ld = 
'installed_local';
 
  276                    $query = 
"UPDATE object_data SET " .
 
  277                            "description = " . 
$ilDB->quote($ld, 
"text") . 
", " .
 
  278                            "last_update = " . 
$ilDB->now() . 
" " .
 
  279                            "WHERE obj_id = " . 
$ilDB->quote($val[
"obj_id"], 
"integer") . 
" " .
 
  280                            "AND type = " . 
$ilDB->quote(
"lng", 
"text");
 
  285                    if (substr($val[
"status"], 0, 9) == 
"installed") {
 
  286                        $query = 
"UPDATE object_data SET " .
 
  287                                "description = " . 
$ilDB->quote(
"not_installed", 
"text") . 
", " .
 
  288                                "last_update = " . 
$ilDB->now() . 
" " .
 
  289                                "WHERE obj_id = " . 
$ilDB->quote($val[
"obj_id"], 
"integer") . 
" " .
 
  290                                "AND type = " . 
$ilDB->quote(
"lng", 
"text");
 
  297        return ($err_lang) ? $err_lang : 
true;
 
  313        $query = 
"SELECT * FROM object_data " .
 
  314                "WHERE type = " . 
$ilDB->quote(
"lng", 
"text") . 
" " .
 
  315                "AND " . 
$ilDB->like(
"description", 
"text", 
'installed%');
 
  318        while ($row = 
$ilDB->fetchObject($r)) {
 
  319            $arr[] = $row->title;
 
  336        $query = 
"SELECT * FROM object_data " .
 
  337                "WHERE type = " . 
$ilDB->quote(
"lng", 
"text") . 
" " .
 
  338                "AND description = " . 
$ilDB->quote(
'installed_local', 
"text");
 
  341        while ($row = 
$ilDB->fetchObject($r)) {
 
  342            $arr[] = $row->title;
 
  358        $query = 
"SELECT * FROM object_data " .
 
  359                "WHERE type = " . 
$ilDB->quote(
"lng", 
"text");
 
  362        while ($row = 
$ilDB->fetchObject($r)) {
 
  363            $arr[$row->title][
"obj_id"] = $row->obj_id;
 
  364            $arr[$row->title][
"status"] = $row->description;
 
  383        $scopeExtension = 
"";
 
  384        if (!empty($scope)) {
 
  385            if ($scope == 
'global') {
 
  388                $scopeExtension = 
'.' . $scope;
 
  393        if ($scope == 
"local") {
 
  394            $path = $this->cust_lang_path;
 
  401        $lang_file = 
"ilias_" . $a_lang_key . 
".lang" . $scopeExtension;
 
  404        if (!is_file($lang_file)) {
 
  410        if (!$content = $this->
cut_header(file($lang_file))) {
 
  416        foreach ($content as $key => $val) {
 
  417            $separated = explode($this->separator, trim($val));
 
  418            $num = count($separated);
 
  444        foreach ($content as $key => $val) {
 
  445            if (trim($val) == 
"<!-- language file start -->") {
 
  446                return array_slice($content, $key + 1);
 
  465        if ($a_mode == 
'all') {
 
  466            $ilDB->manipulate(
"DELETE FROM lng_modules WHERE lang_key = " .
 
  467                $ilDB->quote($a_lang_key, 
"text"));
 
  480        if (!$a_keep_local_change) {
 
  481            $ilDB->manipulate(
"DELETE FROM lng_data WHERE lang_key = " .
 
  482                $ilDB->quote($a_lang_key, 
"text"));
 
  484            $ilDB->manipulate(
"DELETE FROM lng_data WHERE lang_key = " .
 
  485                $ilDB->quote($a_lang_key, 
"text") .
 
  486                " AND local_change IS NULL");
 
  501        if ($a_min_date == 
"") {
 
  502            $a_min_date = 
"1980-01-01 00:00:00";
 
  504        if ($a_max_date == 
"") {
 
  505            $a_max_date = 
"2200-01-01 00:00:00";
 
  509            "SELECT * FROM lng_data WHERE lang_key = %s " .
 
  510            "AND local_change >= %s AND local_change <= %s",
 
  511            $ilDB->quote($a_lang_key, 
"text"),
 
  512            $ilDB->quote($a_min_date, 
"timestamp"),
 
  513            $ilDB->quote($a_max_date, 
"timestamp")
 
  519            $changes[$row[
"module"]][$row[
"identifier"]] = $row[
"value"];
 
  537        $lang_array = array();
 
  539        $scopeExtension = 
"";
 
  540        if (!empty($scope)) {
 
  541            if ($scope == 
'global') {
 
  544                $scopeExtension = 
'.' . $scope;
 
  549        if ($scope == 
"local") {
 
  550            $path = $this->cust_lang_path;
 
  556        $lang_file = 
"ilias_" . 
$lang_key . 
".lang" . $scopeExtension;
 
  558        if (is_file($lang_file)) {
 
  560            $lang_array = array();
 
  561            $lang_array[
"common"] = array();
 
  564            if ($content = $this->
cut_header(file($lang_file))) {
 
  568                } elseif ($scope == 
'local') {
 
  572                    $change_date = date(
"Y-m-d H:i:s", time());
 
  573                    $min_date = date(
"Y-m-d H:i:s", filemtime($lang_file));
 
  577                foreach ($content as $key => $val) {
 
  583                    $separated = explode($this->separator, trim($val));
 
  586                    $pos = strpos($separated[2], $this->comment_separator);
 
  588                    if ($pos !== 
false) {
 
  590                        $separated[2] = substr($separated[2], 0, $pos);
 
  594                    if (isset($local_changes[$separated[0]])) {
 
  595                        $local_value = $local_changes[$separated[0]][$separated[1]];
 
  601                        if ($local_value != 
"" and $local_value != $separated[2]) {
 
  603                            $lang_array[$separated[0]][$separated[1]] = $local_value;
 
  614                            $lang_array[$separated[0]][$separated[1]] = $separated[2];
 
  616                    } elseif ($scope == 
'local') {
 
  617                        if ($local_value != 
"") {
 
  619                            $lang_array[$separated[0]][$separated[1]] = $local_value;
 
  629                            $lang_array[$separated[0]][$separated[1]] = $separated[2];
 
  635            foreach ($lang_array as $module => $lang_arr) {
 
  636                if ($scope == 
"local") {
 
  637                    $q = 
"SELECT * FROM lng_modules WHERE " .
 
  639                        " AND module = " . 
$ilDB->quote($module, 
"text");
 
  640                    $set = 
$ilDB->query($q);
 
  641                    $row = 
$ilDB->fetchAssoc($set);
 
  642                    $arr2 = unserialize($row[
"lang_array"]);
 
  643                    if (is_array($arr2)) {
 
  644                        $lang_arr = array_merge($arr2, $lang_arr);
 
  661        $ilDB->manipulate(sprintf(
 
  662            "DELETE FROM lng_modules WHERE lang_key = %s AND module = %s",
 
  663            $ilDB->quote($a_key, 
"text"),
 
  664            $ilDB->quote($a_module, 
"text")
 
  670        $ilDB->insert(
"lng_modules", array(
 
  671            "lang_key" => array(
"text", $a_key),
 
  672            "module" => array(
"text", $a_module),
 
  673            "lang_array" => array(
"clob", serialize($a_array))
 
  685        $a_local_change = 
null 
  689        $ilDB->manipulate(sprintf(
 
  690            "DELETE FROM lng_data WHERE module = %s AND " .
 
  691            "identifier = %s AND lang_key = %s",
 
  692            $ilDB->quote($a_module, 
"text"),
 
  693            $ilDB->quote($a_identifier, 
"text"),
 
  694            $ilDB->quote($a_lang_key, 
"text")
 
  699        $ilDB->manipulate(sprintf(
 
  700            "INSERT INTO lng_data " .
 
  701            "(module, identifier, lang_key, value, local_change) " .
 
  702            "VALUES (%s,%s,%s,%s,%s)",
 
  703            $ilDB->quote($a_module, 
"text"),
 
  704            $ilDB->quote($a_identifier, 
"text"),
 
  705            $ilDB->quote($a_lang_key, 
"text"),
 
  706            $ilDB->quote($a_value, 
"text"),
 
  707            $ilDB->quote($a_local_change, 
"timestamp")
 
  719        $a_local_change = 
null 
  723        $ilDB->manipulate(sprintf(
 
  725            "SET value = %s, local_change = %s " .
 
  726            "WHERE module = %s AND identifier = %s AND lang_key = %s ",
 
  727            $ilDB->quote($a_value, 
"text"),
 
  728            $ilDB->quote($a_local_change, 
"timestamp"),
 
  729            $ilDB->quote($a_module, 
"text"),
 
  730            $ilDB->quote($a_identifier, 
"text"),
 
  731            $ilDB->quote($a_lang_key, 
"text")
 
  742        $local_langs = array();
 
  743        if (is_dir($this->cust_lang_path)) {
 
  744            $d = dir($this->cust_lang_path);
 
  746            chdir($this->cust_lang_path);
 
  749            while ($entry = 
$d->read()) {
 
  750                if (is_file($entry) && (preg_match(
"~(^ilias_.{2}\.lang.local$)~", $entry))) {
 
  766        $d = dir($this->lang_path);
 
  768        chdir($this->lang_path);
 
  771        while ($entry = 
$d->read()) {
 
  772            if (is_file($entry) && (preg_match(
"~(^ilias_.{2}\.lang$)~", $entry))) {
 
  792        if (empty($a_db_handler) or !is_object($a_db_handler)) {
 
  796        $this->db = &$a_db_handler;
 
An exception for terminatinating execution or to throw for unit testing.
language handling for setup
__construct($a_lang_key)
Constructor read the single-language file and put this in an array text.
cut_header($content)
Remove *.lang header information from '$content'.
static replaceLangModule($a_key, $a_module, $a_array)
Replace language module array.
flushLanguage($a_lang_key, $a_mode='all')
remove language data from database
txt($a_topic, $a_default_lang_fallback_mod='')
gets the text for a given topic
static _deleteLangData($a_lang_key, $a_keep_local_change)
Delete languge data.
insertLanguage($lang_key, $scope='')
insert language data from file in database
getInstalledLanguages()
get already installed languages (in db)
getAvailableLanguages()
get already registered languages (in db)
getInstalledLocalLanguages()
get already installed local languages (in db)
loadLanguageModule($a_module)
static updateLangEntry( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null)
Update lang entry.
getLocalLanguages()
Searches for the existence of *.lang.local files.
getLocalChanges($a_lang_key, $a_min_date="", $a_max_date="")
get locally changed language entries
installLanguages($a_lang_keys, $a_local_keys)
install languages
setDbHandler($a_db_handler)
set db handler object @string object db handler
getLanguages()
get all setup languages in the system
static replaceLangEntry( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null)
Replace lang entry.
checkLanguage($a_lang_key, $scope='')
validate the logical structure of a lang-file
getInstallableLanguages()
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples