19 declare(strict_types=1);
45 public function setLocal(
bool $a_local =
true): void
65 return $this->
lng->txt($this->desc);
107 return self::_getRemarks($this->key);
118 public function getAllValues(array $a_modules = array(),
string $a_pattern =
"", array $a_topics = array()): array
120 return self::_getValues($this->key, $a_modules, $a_topics, $a_pattern);
133 public function getChangedValues(array $a_modules = array(),
string $a_pattern =
"", array $a_topics = array()): array
135 return self::_getValues($this->key, $a_modules, $a_topics, $a_pattern,
"changed");
145 public function getUnchangedValues(array $a_modules = array(),
string $a_pattern =
"", array $a_topics = array()): array
147 return self::_getValues($this->key, $a_modules, $a_topics, $a_pattern,
"unchanged");
158 public function getAddedValues(array $a_modules = array(),
string $a_pattern =
'', array $a_topics = array()): array
161 $global_values = $global_file_obj->getAllValues();
162 $local_values = self::_getValues($this->key, $a_modules, $a_topics, $a_pattern);
164 return array_diff_key($local_values, $global_values);
179 public function getCommentedValues(array $a_modules = array(),
string $a_pattern =
"", array $a_topics = array()): array
182 $global_comments = $global_file_obj->getAllComments();
183 $local_values = self::_getValues($this->key, $a_modules, $a_topics, $a_pattern);
185 return array_intersect_key($local_values, $global_comments);
203 $global_values = $global_file_obj->getAllValues();
204 $local_values = self::_getValues($this->key);
206 return array_merge($global_values, $local_values);
223 $global_comments = $global_file_obj->getAllComments();
226 $local_remarks = self::_getRemarks($this->key,
true);
228 return array_merge($global_comments, $local_remarks);
237 public function importLanguageFile(
string $a_file,
string $a_mode_existing =
"keepnew"):
void 240 $ilDB = $DIC->database();
246 if (!$import_file_obj->read()) {
247 $ilErr->raiseError($import_file_obj->getErrorMessage(),
$ilErr->MESSAGE);
250 switch ($a_mode_existing) {
269 $ilDB->manipulate(
"DELETE FROM lng_modules WHERE lang_key = " .
270 $ilDB->quote($this->key,
"text"));
280 foreach ($import_file_obj->getAllValues() as
$key => $value) {
281 if (!isset($to_keep[$key])) {
282 $to_save[
$key] = $value;
285 self::_saveValues($this->key, $to_save, $import_file_obj->getAllComments());
297 $ilDB = $DIC->database();
299 $q =
"SELECT DISTINCT module FROM lng_data WHERE " .
300 " lang_key = " .
$ilDB->quote($a_lang_key,
"text") .
" order by module";
305 $modules[] = $rec[
"module"];
318 public static function _getRemarks(
string $a_lang_key,
bool $a_all_changed =
false): array
321 $ilDB = $DIC->database();
322 $lng = $DIC->language();
324 $q =
"SELECT module, identifier, remarks" 326 .
" WHERE lang_key = " .
$ilDB->quote($a_lang_key,
"text");
328 if ($a_all_changed) {
329 $q .=
" AND (remarks IS NOT NULL OR local_change IS NOT NULL)";
331 $q .=
" AND remarks IS NOT NULL";
337 while ($row =
$ilDB->fetchAssoc($result)) {
338 $remarks[$row[
"module"] .
$lng->separator . $row[
"identifier"]] = $row[
"remarks"];
356 array $a_modules = array(),
357 array $a_topics = array(),
358 string $a_pattern =
'',
362 $ilDB = $DIC->database();
363 $lng = $DIC->language();
365 $q =
"SELECT * FROM lng_data WHERE" .
366 " lang_key = " .
$ilDB->quote($a_lang_key,
"text") .
" ";
368 if (is_array($a_modules) && count($a_modules) > 0) {
369 $q .=
" AND " .
$ilDB->in(
"module", $a_modules,
false,
"text");
371 if (is_array($a_topics) && count($a_topics) > 0) {
372 $q .=
" AND " .
$ilDB->in(
"identifier", $a_topics,
false,
"text");
375 $q .=
" AND " .
$ilDB->like(
"value",
"text",
"%" . $a_pattern .
"%");
377 if ($a_state ===
"changed") {
378 $q .=
" AND NOT local_change IS NULL ";
380 if ($a_state ===
"unchanged") {
381 $q .=
" AND local_change IS NULL ";
383 $q .=
" ORDER BY module, identifier";
389 $values[$rec[
"module"] .
$lng->separator . $rec[
"identifier"]] = $rec[
"value"];
401 public static function _saveValues(
string $a_lang_key, array $a_values = array(), array $a_remarks = array()): void
404 $ilDB = $DIC->database();
405 $lng = $DIC->language();
407 if (!is_array($a_values)) {
412 ->format(
'Y-m-d H:i:s');
416 $file_values = $global_file_obj->getAllValues();
417 $file_comments = $global_file_obj->getAllComments();
418 $db_values = self::_getValues($a_lang_key);
419 $db_comments = self::_getRemarks($a_lang_key);
420 $global_values = array_merge($db_values, $file_values);
421 $global_comments = array_merge($db_comments, $file_comments);
424 foreach ($a_values as
$key => $value) {
425 $keys = explode(
$lng->separator,
$key);
427 if (count($keys) !== 2) {
431 list($module, $topic) = $keys;
432 $save_array[$module][$topic] = $value;
434 $are_comments_set = array_key_exists(
$key, $global_comments) && array_key_exists(
$key, $a_remarks);
435 $are_changes_made = (isset($global_values[
$key]) ? $global_values[
$key] != $value :
true) || (isset($db_values[$key]) ? $db_values[
$key] != $value :
true);
436 if ($are_changes_made || ($are_comments_set ? $global_comments[$key] != $a_remarks[$key] : $are_comments_set)) {
437 $local_change = (isset($db_values[$key]) ? $db_values[
$key] == $value :
true) || (isset($global_values[$key]) ? $global_values[
$key] != $value :
true) ? $save_date :
null;
444 $a_remarks[$key] ??
null 450 foreach ($save_array as $module => $entries) {
451 $set =
$ilDB->query(sprintf(
452 "SELECT * FROM lng_modules " .
453 "WHERE lang_key = %s AND module = %s",
454 $ilDB->quote($a_lang_key,
"text"),
455 $ilDB->quote($module,
"text")
457 $row =
$ilDB->fetchAssoc($set);
459 $DIC->logger()->root()->warning(
"Language module '{$module}' not found for language {$a_lang_key}.");
463 $entries = self::_mergeLanguageEntriesFromRow($row, $entries);
480 if ($databaseRow ===
null || !isset($databaseRow[
"lang_array"])) {
484 $languageEntries = unserialize($databaseRow[
"lang_array"], [
"allowed_classes" =>
false]);
485 if (!is_array($languageEntries)) {
489 return array_merge($languageEntries, $entries);
499 public static function _deleteValues(
string $a_lang_key, array $a_values = array()): void
502 $ilDB = $DIC->database();
503 $lng = $DIC->language();
505 if (!is_array($a_values)) {
508 $delete_array = array();
511 foreach ($a_values as
$key => $value) {
512 $keys = explode(
$lng->separator,
$key);
513 if (count($keys) === 2) {
516 $delete_array[$module][$topic] = $value;
523 foreach ($delete_array as $module => $entries) {
524 $set =
$ilDB->query(sprintf(
525 "SELECT * FROM lng_modules " .
526 "WHERE lang_key = %s AND module = %s",
527 $ilDB->quote($a_lang_key,
"text"),
528 $ilDB->quote($module,
"text")
530 $row =
$ilDB->fetchAssoc($set);
532 $arr = unserialize($row[
"lang_array"], [
"allowed_classes" =>
false]);
533 if (is_array($arr)) {
534 $entries = array_diff_key($arr, $entries);
getMergedRemarks()
Get the local remarks merged into the remarks of the global language file.
static _deleteLangData(string $a_lang_key, bool $a_keep_local_change=false)
Delete languge data $a_lang_key lang key.
getMergedValues()
Get the local values merged into the values of the global language file.
getAllRemarks()
Get all remarks from the database.
getCustLangPath()
Get the customized language files path.
getChangedValues(array $a_modules=array(), string $a_pattern="", array $a_topics=array())
Get only the changed values from the database which differ from the original language file...
getAllValues(array $a_modules=array(), string $a_pattern="", array $a_topics=array())
Get all values from the database.
getDataPath()
Return the path for language data written by ILIAS.
isInstalled()
Check language object status, and return true if language is installed.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _getValues(string $a_lang_key, array $a_modules=array(), array $a_topics=array(), string $a_pattern='', string $a_state='')
Get the translations of specified topics.
getGlobalLanguageFile()
Read and get the global language file as an object.
getAddedValues(array $a_modules=array(), string $a_pattern='', array $a_topics=array())
Get only the entries which don't exist in the global language file.
static _getModules(string $a_lang_key)
Get all modules of a language.
static _deleteValues(string $a_lang_key, array $a_values=array())
Delete a set of translation in the database.
setLocal(bool $a_local=true)
Set the local status of the language.
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 _mergeLanguageEntriesFromRow(?array $databaseRow, array $entries)
Merge language entries from a database row with existing entries.
getLongDescription()
Get the full language description.
getUnchangedValues(array $a_modules=array(), string $a_pattern="", array $a_topics=array())
Get only the unchanged values from the database which are equal to the original language file...
static _getRemarks(string $a_lang_key, bool $a_all_changed=false)
Get all remarks of a language.
static _getGlobalLanguageFile(string $a_lang_key)
Read and get a global language file as a singleton object $a_lang_key language key.
static replaceLangModule(string $a_key, string $a_module, array $a_array)
Replace language module array.
getLangPath()
Get the language files path.
setDescription(string $description)
getCommentedValues(array $a_modules=array(), string $a_pattern="", array $a_topics=array())
Get all values from the database for wich the global language file has a comment. ...
static _saveValues(string $a_lang_key, array $a_values=array(), array $a_remarks=array())
Save a set of translation in the database.
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static deleteLangEntry(string $a_module, string $a_identifier, string $a_lang_key)
Delete lang entry.