19 declare(strict_types=1);
21 require_once
"./Services/Language/classes/class.ilObjLanguage.php";
39 require_once
"./Services/Language/classes/class.ilLanguageFile.php";
48 public function setLocal(
bool $a_local =
true): void
68 return $this->
lng->txt($this->desc);
110 return self::_getRemarks($this->key);
121 public function getAllValues(array $a_modules = array(),
string $a_pattern =
"", array $a_topics = array()): array
123 return self::_getValues($this->key, $a_modules, $a_topics, $a_pattern);
136 public function getChangedValues(array $a_modules = array(),
string $a_pattern =
"", array $a_topics = array()): array
138 return self::_getValues($this->key, $a_modules, $a_topics, $a_pattern,
"changed");
148 public function getUnchangedValues(array $a_modules = array(),
string $a_pattern =
"", array $a_topics = array()): array
150 return self::_getValues($this->key, $a_modules, $a_topics, $a_pattern,
"unchanged");
161 public function getAddedValues(array $a_modules = array(),
string $a_pattern =
'', array $a_topics = array()): array
164 $global_values = $global_file_obj->getAllValues();
165 $local_values = self::_getValues($this->key, $a_modules, $a_topics, $a_pattern);
167 return array_diff_key($local_values, $global_values);
182 public function getCommentedValues(array $a_modules = array(),
string $a_pattern =
"", array $a_topics = array()): array
185 $global_comments = $global_file_obj->getAllComments();
186 $local_values = self::_getValues($this->key, $a_modules, $a_topics, $a_pattern);
188 return array_intersect_key($local_values, $global_comments);
206 $global_values = $global_file_obj->getAllValues();
207 $local_values = self::_getValues($this->key);
209 return array_merge($global_values, $local_values);
226 $global_comments = $global_file_obj->getAllComments();
229 $local_remarks = self::_getRemarks($this->key,
true);
231 return array_merge($global_comments, $local_remarks);
240 public function importLanguageFile(
string $a_file,
string $a_mode_existing =
"keepnew"):
void 243 $ilDB = $DIC->database();
248 require_once
"./Services/Language/classes/class.ilLanguageFile.php";
250 if (!$import_file_obj->read()) {
251 $ilErr->raiseError($import_file_obj->getErrorMessage(),
$ilErr->MESSAGE);
254 switch ($a_mode_existing) {
273 $ilDB->manipulate(
"DELETE FROM lng_modules WHERE lang_key = " .
274 $ilDB->quote($this->key,
"text"));
284 foreach ($import_file_obj->getAllValues() as
$key => $value) {
285 if (!isset($to_keep[$key])) {
286 $to_save[
$key] = $value;
289 self::_saveValues($this->key, $to_save, $import_file_obj->getAllComments());
301 $ilDB = $DIC->database();
303 $q =
"SELECT DISTINCT module FROM lng_data WHERE " .
304 " lang_key = " .
$ilDB->quote($a_lang_key,
"text") .
" order by module";
309 $modules[] = $rec[
"module"];
322 public static function _getRemarks(
string $a_lang_key,
bool $a_all_changed =
false): array
325 $ilDB = $DIC->database();
326 $lng = $DIC->language();
328 $q =
"SELECT module, identifier, remarks" 330 .
" WHERE lang_key = " .
$ilDB->quote($a_lang_key,
"text");
332 if ($a_all_changed) {
333 $q .=
" AND (remarks IS NOT NULL OR local_change IS NOT NULL)";
335 $q .=
" AND remarks IS NOT NULL";
341 while ($row =
$ilDB->fetchAssoc($result)) {
342 $remarks[$row[
"module"] .
$lng->separator . $row[
"identifier"]] = $row[
"remarks"];
360 array $a_modules = array(),
361 array $a_topics = array(),
362 string $a_pattern =
'',
366 $ilDB = $DIC->database();
367 $lng = $DIC->language();
369 $q =
"SELECT * FROM lng_data WHERE" .
370 " lang_key = " .
$ilDB->quote($a_lang_key,
"text") .
" ";
372 if (is_array($a_modules) && count($a_modules) > 0) {
373 $q .=
" AND " .
$ilDB->in(
"module", $a_modules,
false,
"text");
375 if (is_array($a_topics) && count($a_topics) > 0) {
376 $q .=
" AND " .
$ilDB->in(
"identifier", $a_topics,
false,
"text");
379 $q .=
" AND " .
$ilDB->like(
"value",
"text",
"%" . $a_pattern .
"%");
381 if ($a_state ===
"changed") {
382 $q .=
" AND NOT local_change IS NULL ";
384 if ($a_state ===
"unchanged") {
385 $q .=
" AND local_change IS NULL ";
387 $q .=
" ORDER BY module, identifier";
393 $values[$rec[
"module"] .
$lng->separator . $rec[
"identifier"]] = $rec[
"value"];
405 public static function _saveValues(
string $a_lang_key, array $a_values = array(), array $a_remarks = array()): void
408 $ilDB = $DIC->database();
409 $lng = $DIC->language();
411 if (!is_array($a_values)) {
416 ->format(
'Y-m-d H:i:s');
419 require_once
"./Services/Language/classes/class.ilLanguageFile.php";
421 $file_values = $global_file_obj->getAllValues();
422 $file_comments = $global_file_obj->getAllComments();
423 $db_values = self::_getValues($a_lang_key);
424 $db_comments = self::_getRemarks($a_lang_key);
425 $global_values = array_merge($db_values, $file_values);
426 $global_comments = array_merge($db_comments, $file_comments);
429 foreach ($a_values as
$key => $value) {
430 $keys = explode(
$lng->separator,
$key);
432 if (count($keys) !== 2) {
436 list($module, $topic) = $keys;
437 $save_array[$module][$topic] = $value;
439 $are_comments_set = array_key_exists(
$key, $global_comments) && array_key_exists(
$key, $a_remarks);
440 $are_changes_made = (isset($global_values[
$key]) ? $global_values[
$key] != $value :
true) || (isset($db_values[$key]) ? $db_values[
$key] != $value :
true);
441 if ($are_changes_made || ($are_comments_set ? $global_comments[$key] != $a_remarks[$key] : $are_comments_set)) {
442 $local_change = (isset($db_values[$key]) ? $db_values[
$key] == $value :
true) || (isset($global_values[$key]) ? $global_values[
$key] != $value :
true) ? $save_date : null;
449 $a_remarks[$key] ?? null
455 foreach ($save_array as $module => $entries) {
456 $set =
$ilDB->query(sprintf(
457 "SELECT * FROM lng_modules " .
458 "WHERE lang_key = %s AND module = %s",
459 $ilDB->quote($a_lang_key,
"text"),
460 $ilDB->quote($module,
"text")
462 $row =
$ilDB->fetchAssoc($set);
464 $DIC->logger()->root()->warning(
"Language module '{$module}' not found for language {$a_lang_key}.");
468 $arr = unserialize($row[
"lang_array"], [
"allowed_classes" =>
false]);
469 if (is_array($arr)) {
470 $entries = array_merge($arr, $entries);
472 ilObjLanguage::replaceLangModule($a_lang_key, $module, $entries);
475 require_once(
"class.ilCachedLanguage.php");
485 public static function _deleteValues(
string $a_lang_key, array $a_values = array()): void
488 $ilDB = $DIC->database();
489 $lng = $DIC->language();
491 if (!is_array($a_values)) {
494 $delete_array = array();
497 foreach ($a_values as
$key => $value) {
498 $keys = explode(
$lng->separator,
$key);
499 if (count($keys) === 2) {
502 $delete_array[$module][$topic] = $value;
509 foreach ($delete_array as $module => $entries) {
510 $set =
$ilDB->query(sprintf(
511 "SELECT * FROM lng_modules " .
512 "WHERE lang_key = %s AND module = %s",
513 $ilDB->quote($a_lang_key,
"text"),
514 $ilDB->quote($module,
"text")
516 $row =
$ilDB->fetchAssoc($set);
518 $arr = unserialize($row[
"lang_array"], [
"allowed_classes" =>
false]);
519 if (is_array($arr)) {
520 $entries = array_diff_key($arr, $entries);
522 ilObjLanguage::replaceLangModule($a_lang_key, $module, $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.
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.
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.
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.