53 $il_absolute_path = realpath(__DIR__ .
"/../../../../");
54 $this->lang_path = $il_absolute_path .
"/lang";
55 $this->cust_lang_path = $il_absolute_path .
"/Customizing/global/lang";
65 public function txt(
string $a_topic,
string $a_default_lang_fallback_mod =
''): string
69 if (empty($a_topic)) {
73 $translation = $this->text[$a_topic] ??
'';
76 $pos = strpos($translation, $this->comment_separator);
80 $translation = substr($translation, 0, $pos);
83 if ($translation ===
"") {
84 $log->writeLanguageLog($a_topic, $this->lang_key);
85 return "-" . $a_topic .
"-";
102 if (empty($a_lang_keys)) {
103 $a_lang_keys = array();
106 if (empty($a_local_keys)) {
107 $a_local_keys = array();
114 foreach ($a_lang_keys as $lang_key) {
119 if (in_array($lang_key, $a_local_keys,
true) && is_dir($this->cust_lang_path)) {
128 if (!array_key_exists($lang_key, $db_langs)) {
129 if (in_array($lang_key, $a_local_keys,
true)) {
130 $itype =
"installed_local";
132 $itype =
"installed";
134 $lid = $ilDB->nextId(
"object_data");
135 $query =
"INSERT INTO object_data " .
136 "(obj_id,type,title,description,owner,create_date,last_update) " .
139 $ilDB->quote($lid,
"integer") .
"," .
140 $ilDB->quote(
"lng",
"text") .
"," .
141 $ilDB->quote($lang_key,
"text") .
"," .
142 $ilDB->quote($itype,
"text") .
"," .
143 $ilDB->quote(
"-1",
"integer") .
"," .
147 $ilDB->manipulate(
$query);
154 foreach ($db_langs as
$key => $val) {
155 if (!in_array(
$key, $err_lang,
true)) {
156 if (in_array(
$key, $a_lang_keys,
true)) {
157 if (in_array(
$key, $a_local_keys,
true)) {
158 $ld =
"installed_local";
162 $query =
"UPDATE object_data SET " .
163 "description = " . $ilDB->quote($ld,
"text") .
", " .
164 "last_update = " . $ilDB->now() .
" " .
165 "WHERE obj_id = " . $ilDB->quote($val[
"obj_id"],
"integer") .
" " .
166 "AND type = " . $ilDB->quote(
"lng",
"text");
167 $ilDB->manipulate(
$query);
171 if (strpos($val[
"status"],
"installed") === 0) {
172 $query =
"UPDATE object_data SET " .
173 "description = " . $ilDB->quote(
"not_installed",
"text") .
", " .
174 "last_update = " . $ilDB->now() .
" " .
175 "WHERE obj_id = " . $ilDB->quote($val[
"obj_id"],
"integer") .
" " .
176 "AND type = " . $ilDB->quote(
"lng",
"text");
177 $ilDB->manipulate(
$query);
183 return ($err_lang) ?:
true;
196 $query =
"SELECT * FROM object_data " .
197 "WHERE type = " . $ilDB->quote(
"lng",
"text") .
" " .
198 "AND " . $ilDB->like(
"description",
"text",
"installed%");
199 $r = $ilDB->query(
$query);
201 while ($row = $ilDB->fetchObject($r)) {
202 $arr[] = $row->title;
216 $query =
"SELECT * FROM object_data " .
217 "WHERE type = " . $ilDB->quote(
"lng",
"text") .
" " .
218 "AND description = " . $ilDB->quote(
"installed_local",
"text");
219 $r = $ilDB->query(
$query);
221 while ($row = $ilDB->fetchObject($r)) {
222 $arr[] = $row->title;
237 $query =
"SELECT * FROM object_data " .
238 "WHERE type = " . $ilDB->quote(
"lng",
"text");
239 $r = $ilDB->query(
$query);
241 while ($row = $ilDB->fetchObject($r)) {
242 $arr[$row->title][
"obj_id"] = $row->obj_id;
243 $arr[$row->title][
"status"] = $row->description;
262 $scopeExtension =
"";
264 if (
$scope ===
"global") {
267 $scopeExtension =
"." .
$scope;
280 $lang_file =
"ilias_" . $a_lang_key .
".lang" . $scopeExtension;
283 if (!is_file($lang_file)) {
289 if (!$content = $this->
cut_header(file($lang_file))) {
295 foreach ($content as
$key => $val) {
296 $separated = explode($this->separator, trim($val));
297 $num = count($separated);
323 foreach ($content as
$key => $val) {
324 if (trim($val) ===
"<!-- language file start -->") {
325 return array_slice($content,
$key + 1);
336 protected function flushLanguage(
string $a_lang_key,
string $a_mode =
"all"): void
340 self::_deleteLangData($a_lang_key, ($a_mode ===
"keep_local"));
342 if ($a_mode ===
"all") {
343 $ilDB->manipulate(
"DELETE FROM lng_modules WHERE lang_key = " .
344 $ilDB->quote($a_lang_key,
"text"));
353 public static function _deleteLangData(
string $a_lang_key,
bool $a_keep_local_change): void
357 if (!$a_keep_local_change) {
358 $ilDB->manipulate(
"DELETE FROM lng_data WHERE lang_key = " .
359 $ilDB->quote($a_lang_key,
"text"));
361 $ilDB->manipulate(
"DELETE FROM lng_data WHERE lang_key = " .
362 $ilDB->quote($a_lang_key,
"text") .
363 " AND local_change IS NULL");
374 public function getLocalChanges(
string $a_lang_key,
string $a_min_date =
"",
string $a_max_date =
""): array
378 if ($a_min_date ===
"") {
379 $a_min_date =
"1980-01-01 00:00:00";
381 if ($a_max_date ===
"") {
382 $a_max_date =
"2200-01-01 00:00:00";
386 "SELECT * FROM lng_data WHERE lang_key = %s " .
387 "AND local_change >= %s AND local_change <= %s",
388 $ilDB->quote($a_lang_key,
"text"),
389 $ilDB->quote($a_min_date,
"timestamp"),
390 $ilDB->quote($a_max_date,
"timestamp")
392 $result = $ilDB->query($q);
396 $changes[$row[
"module"]][$row[
"identifier"]] = $row[
"value"];
413 $lang_array = array();
415 $scopeExtension =
"";
417 if (
$scope ===
"global") {
420 $scopeExtension =
"." .
$scope;
432 $lang_file =
"ilias_" . $lang_key .
".lang" . $scopeExtension;
435 if (is_file($lang_file)) {
438 $lang_array[
"common"] = [];
441 if ($content = $this->
cut_header(file($lang_file))) {
445 } elseif (
$scope ===
"local") {
449 $change_date = date(
"Y-m-d H:i:s", time());
450 $min_date = date(
"Y-m-d H:i:s", filemtime($lang_file));
454 $query_check =
false;
455 $query =
"INSERT INTO lng_data (module,identifier,lang_key,value,local_change,remarks) VALUES ";
456 foreach ($content as
$key => $val) {
462 $separated = explode($this->separator, trim($val));
465 $pos = strpos($separated[2], $this->comment_separator);
467 if ($pos !==
false) {
469 $separated[2] = substr($separated[2], 0, $pos);
473 if (isset($local_changes[$separated[0]])) {
474 $local_value = $local_changes[$separated[0]][$separated[1]] ??
"";
480 if ($local_value !==
"" && $local_value !== $separated[2]) {
482 $lang_array[$separated[0]][$separated[1]] = $local_value;
485 } elseif (
$scope ===
"local") {
486 if ($local_value !==
"") {
488 $lang_array[$separated[0]][$separated[1]] = $local_value;
494 "(%s,%s,%s,%s,%s,%s),",
495 $ilDB->quote($separated[0],
"text"),
496 $ilDB->quote($separated[1],
"text"),
497 $ilDB->quote($lang_key,
"text"),
498 $ilDB->quote($separated[2],
"text"),
499 $ilDB->quote($change_date,
"timestamp"),
500 $ilDB->quote($separated[3] ?? null,
"text")
503 $lang_array[$separated[0]][$separated[1]] = $separated[2];
505 $query = rtrim(
$query,
",") .
" ON DUPLICATE KEY UPDATE value=VALUES(value),remarks=VALUES(remarks);";
507 $ilDB->manipulate(
$query);
511 $query =
"INSERT INTO lng_modules (module, lang_key, lang_array) VALUES ";
512 $modules_to_delete = [];
513 foreach ($lang_array as $module => $lang_arr) {
515 $q =
"SELECT * FROM lng_modules WHERE " .
516 " lang_key = " . $ilDB->quote($lang_key,
"text") .
517 " AND module = " . $ilDB->quote($module,
"text");
518 $set = $ilDB->query($q);
519 $row = $ilDB->fetchAssoc($set);
520 $arr2 = unserialize($row[
"lang_array"], [
"allowed_classes" =>
false]);
521 if (is_array($arr2)) {
522 $lang_arr = array_merge($arr2, $lang_arr);
527 $ilDB->quote($module,
"text"),
528 $ilDB->quote($lang_key,
"text"),
529 $ilDB->quote(serialize($lang_arr),
"clob"),
531 $modules_to_delete[] = $module;
534 $inModulesToDelete = $ilDB->in(
'module', $modules_to_delete,
false,
'text');
535 $ilDB->manipulate(sprintf(
"DELETE FROM lng_modules WHERE lang_key = %s AND $inModulesToDelete",
536 $ilDB->quote($lang_key,
"text")
540 $ilDB->manipulate(
$query);
552 $local_langs = array();
553 if (is_dir($this->cust_lang_path)) {
554 $d = dir($this->cust_lang_path);
556 chdir($this->cust_lang_path);
559 while ($entry =
$d->read()) {
560 if (is_file($entry) && (preg_match(
"~(^ilias_.{2}\.lang.local$)~", $entry))) {
561 $lang_key = substr($entry, 6, 2);
577 $d = dir($this->lang_path);
579 chdir($this->lang_path);
581 $installableLanguages = [];
583 while ($entry =
$d->read()) {
584 if (is_file($entry) && (preg_match(
"~(^ilias_.{2}\.lang$)~", $entry))) {
585 $lang_key = substr($entry, 6, 2);
592 return $installableLanguages;
602 $this->db = &$a_db_handler;
getInstallableLanguages()
Return installable languages.
flushLanguage(string $a_lang_key, string $a_mode="all")
remove language data from database $a_lang_key language key $a_mode "all" or "keep_local" ...
string $comment_separator
getLocalChanges(string $a_lang_key, string $a_min_date="", string $a_max_date="")
get locally changed language entries $a_lang_key language key $a_min_date minimum change date "yyyy-m...
__construct(string $a_lang_key)
txt(string $a_topic, string $a_default_lang_fallback_mod='')
gets the text for a given topic
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cut_header(array $content)
Remove *.lang header information from '$content'.
checkLanguage(string $a_lang_key, string $scope="")
validate the logical structure of a lang-file
installLanguages(array $a_lang_keys, array $a_local_keys)
install languages
getInstalledLanguages()
get already installed languages (in db)
getInstalledLocalLanguages()
get already installed local languages (in db)
loadLanguageModule(string $a_module)
getAvailableLanguages()
get already registered languages (in db)
getLocalLanguages()
Searches for the existence of *.lang.local files.
insertLanguage(string $lang_key, string $scope="")
insert language data from file in database
setDbHandler(ilDBInterface $a_db_handler)
set db handler object object db handler Return true on success
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
static _deleteLangData(string $a_lang_key, bool $a_keep_local_change)
Delete languge data.