19 declare(strict_types=1);
55 $il_absolute_path = realpath(__DIR__ .
"/../../../../../");
56 $this->lang_path = $il_absolute_path .
"/lang";
57 $this->cust_lang_path = $il_absolute_path .
"/lang/customizing";
67 public function txt(
string $a_topic,
string $a_default_lang_fallback_mod =
''): string
71 if (empty($a_topic)) {
75 $translation = $this->text[$a_topic] ??
'';
78 $pos = strpos($translation, $this->comment_separator);
82 $translation = substr($translation, 0, $pos);
85 if ($translation ===
"") {
86 $log->writeLanguageLog($a_topic, $this->lang_key);
87 return "-" . $a_topic .
"-";
104 if (empty($a_lang_keys)) {
105 $a_lang_keys = array();
108 if (empty($a_local_keys)) {
109 $a_local_keys = array();
116 foreach ($a_lang_keys as $lang_key) {
121 if (in_array($lang_key, $a_local_keys,
true) && is_dir($this->cust_lang_path)) {
130 if (!array_key_exists($lang_key, $db_langs)) {
131 if (in_array($lang_key, $a_local_keys,
true)) {
132 $itype =
"installed_local";
134 $itype =
"installed";
136 $lid = $ilDB->nextId(
"object_data");
137 $query =
"INSERT INTO object_data " .
138 "(obj_id,type,title,description,owner,create_date,last_update) " .
141 $ilDB->quote($lid,
"integer") .
"," .
142 $ilDB->quote(
"lng",
"text") .
"," .
143 $ilDB->quote($lang_key,
"text") .
"," .
144 $ilDB->quote($itype,
"text") .
"," .
145 $ilDB->quote(
"-1",
"integer") .
"," .
149 $ilDB->manipulate($query);
156 foreach ($db_langs as $key => $val) {
157 if (!in_array($key, $err_lang,
true)) {
158 if (in_array($key, $a_lang_keys,
true)) {
159 if (in_array($key, $a_local_keys,
true)) {
160 $ld =
"installed_local";
164 $query =
"UPDATE object_data SET " .
165 "description = " . $ilDB->quote($ld,
"text") .
", " .
166 "last_update = " . $ilDB->quote(gmdate(
"Y-m-d H:i:s"),
"timestamp") .
" " .
167 "WHERE obj_id = " . $ilDB->quote($val[
"obj_id"],
"integer") .
" " .
168 "AND type = " . $ilDB->quote(
"lng",
"text");
169 $ilDB->manipulate($query);
173 if (strpos($val[
"status"],
"installed") === 0) {
174 $query =
"UPDATE object_data SET " .
175 "description = " . $ilDB->quote(
"not_installed",
"text") .
", " .
176 "last_update = " . $ilDB->quote(gmdate(
"Y-m-d H:i:s"),
"timestamp") .
" " .
177 "WHERE obj_id = " . $ilDB->quote($val[
"obj_id"],
"integer") .
" " .
178 "AND type = " . $ilDB->quote(
"lng",
"text");
179 $ilDB->manipulate($query);
185 return ($err_lang) ?:
true;
197 $query =
"SELECT * FROM object_data " .
198 "WHERE type = " . $ilDB->quote(
"lng",
"text") .
" " .
199 "AND " . $ilDB->like(
"description",
"text",
"installed%");
200 $r = $ilDB->query($query);
202 while ($row = $ilDB->fetchObject(
$r)) {
203 $arr[] = $row->title;
218 $query =
"SELECT * FROM object_data " .
219 "WHERE type = " . $ilDB->quote(
"lng",
"text") .
" " .
220 "AND description = " . $ilDB->quote(
"installed_local",
"text");
221 $r = $ilDB->query($query);
223 while ($row = $ilDB->fetchObject(
$r)) {
224 $arr[] = $row->title;
239 $query =
"SELECT * FROM object_data " .
240 "WHERE type = " . $ilDB->quote(
"lng",
"text");
241 $r = $ilDB->query($query);
243 while ($row = $ilDB->fetchObject(
$r)) {
244 $arr[$row->title][
"obj_id"] = $row->obj_id;
245 $arr[$row->title][
"status"] = $row->description;
264 $scopeExtension =
"";
266 if (
$scope ===
"global") {
269 $scopeExtension =
"." .
$scope;
282 $lang_file =
"ilias_" . $a_lang_key .
".lang" . $scopeExtension;
285 if (!is_file($lang_file)) {
291 if (!$content = $this->
cut_header(file($lang_file))) {
297 foreach ($content as $key => $val) {
298 $separated = explode($this->separator, trim($val));
299 $num = count($separated);
325 foreach ($content as $key => $val) {
326 if (trim($val) ===
"<!-- language file start -->") {
327 return array_slice($content, $key + 1);
338 protected function flushLanguage(
string $a_lang_key,
string $a_mode =
"all"): void
342 self::_deleteLangData($a_lang_key, ($a_mode ===
"keep_local"));
344 if ($a_mode ===
"all") {
345 $ilDB->manipulate(
"DELETE FROM lng_modules WHERE lang_key = " .
346 $ilDB->quote($a_lang_key,
"text"));
355 public static function _deleteLangData(
string $a_lang_key,
bool $a_keep_local_change): void
359 if (!$a_keep_local_change) {
360 $ilDB->manipulate(
"DELETE FROM lng_data WHERE lang_key = " .
361 $ilDB->quote($a_lang_key,
"text"));
363 $ilDB->manipulate(
"DELETE FROM lng_data WHERE lang_key = " .
364 $ilDB->quote($a_lang_key,
"text") .
365 " AND local_change IS NULL");
376 public function getLocalChanges(
string $a_lang_key,
string $a_min_date =
"",
string $a_max_date =
""): array
380 if ($a_min_date ===
"") {
381 $a_min_date =
"1980-01-01 00:00:00";
383 if ($a_max_date ===
"") {
384 $a_max_date =
"2200-01-01 00:00:00";
388 "SELECT * FROM lng_data WHERE lang_key = %s " .
389 "AND local_change >= %s AND local_change <= %s",
390 $ilDB->quote($a_lang_key,
"text"),
391 $ilDB->quote($a_min_date,
"timestamp"),
392 $ilDB->quote($a_max_date,
"timestamp")
394 $result = $ilDB->query(
$q);
398 $changes[$row[
"module"]][$row[
"identifier"]] = $row[
"value"];
415 $lang_array = array();
417 $scopeExtension =
"";
419 if (
$scope ===
"global") {
422 $scopeExtension =
"." .
$scope;
434 $lang_file =
"ilias_" . $lang_key .
".lang" . $scopeExtension;
437 if (is_file($lang_file)) {
440 $lang_array[
"common"] = [];
443 if ($content = $this->
cut_header(file($lang_file))) {
447 } elseif (
$scope ===
"local") {
451 $change_date = gmdate(
"Y-m-d H:i:s", time());
452 $min_date = gmdate(
"Y-m-d H:i:s", filemtime($lang_file));
456 $query_check =
false;
457 $query =
"INSERT INTO lng_data (module,identifier,lang_key,value,local_change,remarks) VALUES ";
458 foreach ($content as $key => $val) {
464 $separated = explode($this->separator, trim($val));
467 $pos = strpos($separated[2], $this->comment_separator);
469 if ($pos !==
false) {
471 $separated[2] = substr($separated[2], 0, $pos);
475 if (isset($local_changes[$separated[0]])) {
476 $local_value = $local_changes[$separated[0]][$separated[1]] ??
"";
482 if ($local_value !==
"" && $local_value !== $separated[2]) {
484 $lang_array[$separated[0]][$separated[1]] = $local_value;
487 } elseif (
$scope ===
"local") {
488 if ($local_value !==
"") {
490 $lang_array[$separated[0]][$separated[1]] = $local_value;
496 "(%s,%s,%s,%s,%s,%s),",
497 $ilDB->quote($separated[0],
"text"),
498 $ilDB->quote($separated[1],
"text"),
499 $ilDB->quote($lang_key,
"text"),
500 $ilDB->quote($separated[2],
"text"),
501 $ilDB->quote($change_date,
"timestamp"),
502 $ilDB->quote($separated[3] ??
null,
"text")
505 $lang_array[$separated[0]][$separated[1]] = $separated[2];
507 $query = rtrim($query,
",") .
" ON DUPLICATE KEY UPDATE value=VALUES(value),remarks=VALUES(remarks);";
509 $ilDB->manipulate($query);
513 $query =
"INSERT INTO lng_modules (module, lang_key, lang_array) VALUES ";
514 $modules_to_delete = [];
515 foreach ($lang_array as $module => $lang_arr) {
517 $q =
"SELECT * FROM lng_modules WHERE " .
518 " lang_key = " . $ilDB->quote($lang_key,
"text") .
519 " AND module = " . $ilDB->quote($module,
"text");
520 $set = $ilDB->query(
$q);
521 $row = $ilDB->fetchAssoc($set);
522 $arr2 = unserialize($row[
"lang_array"], [
"allowed_classes" =>
false]);
523 if (is_array($arr2)) {
524 $lang_arr = array_merge($arr2, $lang_arr);
529 $ilDB->quote($module,
"text"),
530 $ilDB->quote($lang_key,
"text"),
531 $ilDB->quote(serialize($lang_arr),
"clob"),
533 $modules_to_delete[] = $module;
536 $inModulesToDelete = $ilDB->in(
'module', $modules_to_delete,
false,
'text');
537 $ilDB->manipulate(sprintf(
538 "DELETE FROM lng_modules WHERE lang_key = %s AND $inModulesToDelete",
539 $ilDB->quote($lang_key,
"text")
542 $query = rtrim($query,
",") .
";";
543 $ilDB->manipulate($query);
555 $local_langs = array();
556 if (is_dir($this->cust_lang_path)) {
557 $d = dir($this->cust_lang_path);
559 chdir($this->cust_lang_path);
562 while ($entry =
$d->read()) {
563 if (is_file($entry) && (preg_match(
"~(^ilias_.{2}\.lang.local$)~", $entry))) {
564 $lang_key = substr($entry, 6, 2);
580 $d = dir($this->lang_path);
582 chdir($this->lang_path);
584 $installableLanguages = [];
586 while ($entry =
$d->read()) {
587 if (is_file($entry) && (preg_match(
"~(^ilias_.{2}\.lang$)~", $entry))) {
588 $lang_key = substr($entry, 6, 2);
595 return $installableLanguages;
605 $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
language handling for setup
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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
static _deleteLangData(string $a_lang_key, bool $a_keep_local_change)
Delete languge data.