19declare(strict_types=1);
50 public function __construct(
int $a_id = 0,
bool $a_call_by_reference =
false)
61 $this->lang_default =
$lng->lang_default;
62 $this->lang_user =
$lng->lang_user;
63 $this->lang_path =
$lng->lang_path;
65 $this->separator =
$lng->separator;
66 $this->comment_separator =
$lng->comment_separator;
77 foreach ($languages as $lang) {
79 if ($langObj->isInstalled()) {
80 $objects[] = $langObj;
98 if ($lang[
'desc'] ===
'installed') {
99 $lang_keys[] = $lang[
'title'];
131 if ($this->key == $this->lang_default) {
143 if ($this->key == $this->lang_user) {
157 if (str_starts_with($this->
getStatus(),
"installed")) {
172 if (substr($this->
getStatus(), 10) ===
"local") {
188 if (
$scope ===
"global") {
191 $scopeExtension =
"." .
$scope;
199 $this->
flush(
"keep_local");
208 $newDesc =
"installed";
209 } elseif (
$scope ===
"local") {
210 $newDesc =
"installed_local";
228 if ((str_starts_with($this->status,
"installed")) && ($this->key != $this->lang_default) && ($this->key != $this->lang_user)) {
247 $this->
flush(
"keep_local");
272 $refreshed = array();
274 foreach ($languages as $lang) {
276 if ($langObj->refresh()) {
277 $refreshed[] = $langObj->getKey();
294 $component_repository =
$DIC[
"component.repository"];
295 foreach ($component_repository->getPlugins() as
$plugin) {
300 $handler->updateLanguages($a_lang_keys);
309 public static function _deleteLangData(
string $a_lang_key,
bool $a_keep_local_change =
false): void
314 if (!$a_keep_local_change) {
315 $ilDB->manipulate(
"DELETE FROM lng_data WHERE lang_key = " .
316 $ilDB->quote($a_lang_key,
"text"));
318 $ilDB->manipulate(
"DELETE FROM lng_data WHERE lang_key = " .
319 $ilDB->quote($a_lang_key,
"text") .
320 " AND local_change IS NULL");
328 public function flush(
string $a_mode =
"all"): void
335 if ($a_mode ===
"all") {
336 $ilDB->manipulate(
"DELETE FROM lng_modules WHERE lang_key = " .
337 $ilDB->quote($this->key,
"text"));
348 public function getLocalChanges(
string $a_min_date =
"",
string $a_max_date =
""): array
353 if ($a_min_date ===
"") {
354 $a_min_date =
"1980-01-01 00:00:00";
356 if ($a_max_date ===
"") {
357 $a_max_date =
"2200-01-01 00:00:00";
361 "SELECT * FROM lng_data WHERE lang_key = %s " .
362 "AND local_change >= %s AND local_change <= %s",
363 $ilDB->quote($this->key,
"text"),
364 $ilDB->quote($a_min_date,
"timestamp"),
365 $ilDB->quote($a_max_date,
"timestamp")
371 $changes[$row[
"module"]][$row[
"identifier"]] = $row[
"value"];
388 "SELECT MAX(local_change) last_change FROM lng_data " .
389 "WHERE lang_key = %s AND local_change IS NOT NULL",
390 $ilDB->quote($a_key,
"text")
395 return (
string) $row[
"last_change"];
414 $result =
$ilDB->queryF(
415 "SELECT * FROM lng_data WHERE lang_key = %s AND module = %s AND local_change IS NOT NULL",
416 array(
"text",
"text"),
417 array($a_key, $a_module)
420 while ($row =
$ilDB->fetchAssoc($result)) {
421 $changes[$row[
"identifier"]] = $row[
"value"];
436 $scopeExtension =
"";
438 if (
$scope ===
"global") {
441 $scopeExtension =
"." .
$scope;
450 $lang_file =
$path .
"/ilias_" . $this->key .
".lang" . $scopeExtension;
452 if (is_file($lang_file)) {
454 if ($content = self::cut_header(file($lang_file))) {
455 $local_changes =
null;
459 } elseif (
$scope ===
"local") {
462 $min_date = gmdate(
"Y-m-d H:i:s", filemtime($lang_file));
466 $lang_array = $dbAccess->insertLangEntries($lang_file);
467 $dbAccess->replaceLangModules($lang_array);
475 final public static function replaceLangModule(
string $a_key,
string $a_module, array $a_array): void
483 $ilDB->manipulate(sprintf(
484 "DELETE FROM lng_modules WHERE lang_key = %s AND module = %s",
485 $ilDB->quote($a_key,
"text"),
486 $ilDB->quote($a_module,
"text")
493 $ilDB->insert(
"lng_modules", array(
494 "lang_key" => array(
"text", $a_key),
495 "module" => array(
"text", $a_module),
496 "lang_array" => array(
"clob", serialize($a_array))
501 $result =
$ilDB->queryF(
502 "SELECT lang_array FROM lng_modules WHERE lang_key = %s AND module = %s",
503 array(
"text",
"text"),
504 array($a_key, $a_module)
506 $row =
$ilDB->fetchAssoc($result);
508 $unserialied = unserialize($row[
"lang_array"], [
"allowed_classes" =>
false]);
509 if (!is_array($unserialied)) {
510 $DIC->ui()->mainTemplate()->setOnScreenMessage(
512 "Data for module '" . $a_module .
"' of language '" . $a_key .
"' is not correctly saved. " .
513 "Please check the collation of your database tables lng_data and lng_modules. It must be utf8_unicode_ci.",
516 $DIC->ctrl()->redirectByClass(ilobjlanguagefoldergui::class,
'view');
525 string $a_identifier,
528 ?
string $a_local_change =
null,
529 ?
string $a_remarks =
null
537 if (is_string($a_remarks) && $a_remarks !==
'') {
538 $a_remarks = substr($a_remarks, 0, 250);
541 if ($a_remarks ===
'') {
545 if ($a_value ===
"") {
548 $a_value = substr($a_value, 0, 4000);
554 "module" => array(
"text",$a_module),
555 "identifier" => array(
"text",$a_identifier),
556 "lang_key" => array(
"text",$a_lang_key)
559 "value" => array(
"text",$a_value),
560 "local_change" => array(
"timestamp",$a_local_change),
561 "remarks" => array(
"text", $a_remarks)
572 string $a_identifier,
575 ?
string $a_local_change =
null,
576 ?
string $a_remarks =
null
581 if (is_string($a_remarks) && $a_remarks !==
'') {
582 $a_remarks = substr($a_remarks, 0, 250);
585 if ($a_remarks ===
'') {
589 if ($a_value ===
"") {
592 $a_value = substr($a_value, 0, 4000);
595 $ilDB->manipulate(sprintf(
597 "SET value = %s, local_change = %s, remarks = %s " .
598 "WHERE module = %s AND identifier = %s AND lang_key = %s ",
599 $ilDB->quote($a_value,
"text"),
600 $ilDB->quote($a_local_change,
"timestamp"),
601 $ilDB->quote($a_remarks,
"text"),
602 $ilDB->quote($a_module,
"text"),
603 $ilDB->quote($a_identifier,
"text"),
604 $ilDB->quote($a_lang_key,
"text")
612 final public static function deleteLangEntry(
string $a_module,
string $a_identifier,
string $a_lang_key): bool
617 $ilDB->manipulate(sprintf(
618 "DELETE FROM lng_data " .
619 "WHERE module = %s AND identifier = %s AND lang_key = %s ",
620 $ilDB->quote($a_module,
"text"),
621 $ilDB->quote($a_identifier,
"text"),
622 $ilDB->quote($a_lang_key,
"text")
640 $query =
"UPDATE usr_pref SET " .
641 "value = " .
$ilDB->quote($this->lang_default,
"text") .
" " .
642 "WHERE keyword = " .
$ilDB->quote(
'language',
"text") .
" " .
643 "AND value = " .
$ilDB->quote($lang_key,
"text");
644 $ilDB->manipulate($query);
658 foreach ($content as $key => $val) {
659 if (trim($val) ===
"<!-- language file start -->") {
660 return array_slice($content, $key + 1);
691 $scopeExtension =
"";
693 if (
$scope ===
"global") {
696 $scopeExtension =
"." .
$scope;
700 $path = $this->lang_path;
702 $path = $this->cust_lang_path;
708 if (!is_dir(
$path)) {
709 $DIC->ui()->mainTemplate()->setOnScreenMessage(
711 "Directory not found: " .
$path,
714 $DIC->ctrl()->redirectByClass(ilobjlanguagefoldergui::class,
'view');
720 $lang_file =
"ilias_" . $this->key .
".lang" . $scopeExtension;
723 if (!is_file($lang_file)) {
724 $DIC->ui()->mainTemplate()->setOnScreenMessage(
726 "File not found: " . $lang_file,
729 $DIC->ctrl()->redirectByClass(ilobjlanguagefoldergui::class,
'view');
733 $content = self::cut_header(file($lang_file));
734 if ($content ===
false) {
735 $DIC->ui()->mainTemplate()->setOnScreenMessage(
737 "Wrong Header in " . $lang_file,
740 $DIC->ctrl()->redirectByClass(ilobjlanguagefoldergui::class,
'view');
746 foreach ($content as $key => $val) {
747 $separated = explode($this->separator, trim($val));
748 $num = count($separated);
752 $DIC->ui()->mainTemplate()->setOnScreenMessage(
754 "Wrong parameter count in " . $lang_file .
" in line $line (Value: $val)! Please check your language file!",
757 $DIC->ctrl()->redirectByClass(ilobjlanguagefoldergui::class,
'view');
760 $DIC->ui()->mainTemplate()->setOnScreenMessage(
762 "Non UTF8 character found in " . $lang_file .
" in line $line (Value: $val)! Please check your language file!",
765 $DIC->ctrl()->redirectByClass(ilobjlanguagefoldergui::class,
'view');
784 $set =
$ilDB->query(
"SELECT COUNT(*) cnt FROM usr_data ud JOIN usr_pref up" .
785 " ON ud.usr_id = up.usr_id " .
786 " WHERE up.value = " .
$ilDB->quote($a_lang,
"text") .
787 " AND up.keyword = " .
$ilDB->quote(
"language",
"text"));
788 $rec =
$ilDB->fetchAssoc($set);
791 if ($a_lang ==
$lng->lang_default) {
792 $set2 =
$ilDB->query(
"SELECT COUNT(*) cnt FROM usr_data ud LEFT JOIN usr_pref up" .
793 " ON (ud.usr_id = up.usr_id AND up.keyword = " .
$ilDB->quote(
"language",
"text") .
")" .
794 " WHERE up.value IS NULL ");
795 $rec2 =
$ilDB->fetchAssoc($set2);
798 return (
int) $rec[
"cnt"] + (
int) ($rec2[
"cnt"] ?? 0);
flush(string $a_mode="all")
remove language data from database $a_mode "all" or "keep_local"
static _deleteLangData(string $a_lang_key, bool $a_keep_local_change=false)
Delete languge data $a_lang_key lang key.
static deleteLangEntry(string $a_module, string $a_identifier, string $a_lang_key)
Delete lang entry.
resetUserLanguage(string $lang_key)
search ILIAS for users which have selected '$lang_key' as their prefered language and reset them to d...
static updateLangEntry(string $a_module, string $a_identifier, string $a_lang_key, string $a_value, ?string $a_local_change=null, ?string $a_remarks=null)
Replace lang entry.
string $comment_separator
string $separator
separator of module, comment separator, identifier & values in language files
static _getLastLocalChange(string $a_key)
get the date of the last local change $a_key language key Return change_date "yyyy-mm-dd hh:mm:ss"
static refreshAll()
Refresh all installed languages.
isInstalled()
Check language object status, and return true if language is installed.
uninstall()
uninstall current language
getStatus()
get language status
isLocal()
Check language object status, and return true if a local language file is installed.
static getInstalledLanguages()
Get the language objects of the installed languages.
install(string $scope="")
install current language
check(string $scope="")
Validate the logical structure of a lang file.
static getLangKeysOfInstalledLanguages()
Return the language keys of the installed languages.
isSystemLanguage()
check if language is system language
isUserLanguage()
check if language is system language
static refreshPlugins(?array $a_lang_keys=null)
Refresh languages of activated plugins $a_lang_keys keys of languages to be refreshed (not yet suppor...
static replaceLangEntry(string $a_module, string $a_identifier, string $a_lang_key, string $a_value, ?string $a_local_change=null, ?string $a_remarks=null)
Replace lang entry.
static replaceLangModule(string $a_key, string $a_module, array $a_array)
Replace language module array.
insert(string $scope="")
insert language data from file into database
static _getLocalChangesByModule(string $a_key, string $a_module)
Get the local changes of a language module $a_key Language key $a_module Module key Return array iden...
refresh()
refresh current language
static cut_header(array $content)
remove lang-file haeder information from '$content' This function seeks for a special keyword where t...
static countUsers(string $a_lang)
Count number of users that use a language.
optimizeData()
optimizes the db-table langdata
__construct(int $a_id=0, bool $a_call_by_reference=false)
Constructor.
getLocalChanges(string $a_min_date="", string $a_max_date="")
get locally changed language entries $a_min_date minimum change date "yyyy-mm-dd hh:mm:ss" $a_max_dat...
Class ilObject Basic functions for all objects.
static _getObjectsByType(string $obj_type="", ?int $owner=null)
setDescription(string $description)
static isUtf8(string $a_str)
Check whether string is utf-8.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc