19 declare(strict_types=1);
37 require_once
"./Services/Language/classes/class.ilLanguageFile.php";
46 public function setLocal(
bool $a_local =
true): void
66 return $this->
lng->txt($this->desc);
108 return self::_getRemarks($this->key);
119 public function getAllValues(array $a_modules = array(),
string $a_pattern =
"", array $a_topics = array()): array
121 return self::_getValues($this->key, $a_modules, $a_topics, $a_pattern);
134 public function getChangedValues(array $a_modules = array(),
string $a_pattern =
"", array $a_topics = array()): array
136 return self::_getValues($this->key, $a_modules, $a_topics, $a_pattern,
"changed");
146 public function getUnchangedValues(array $a_modules = array(),
string $a_pattern =
"", array $a_topics = array()): array
148 return self::_getValues($this->key, $a_modules, $a_topics, $a_pattern,
"unchanged");
159 public function getAddedValues(array $a_modules = array(),
string $a_pattern =
'', array $a_topics = array()): array
162 $global_values = $global_file_obj->getAllValues();
163 $local_values = self::_getValues($this->key, $a_modules, $a_topics, $a_pattern);
165 return array_diff_key($local_values, $global_values);
180 public function getCommentedValues(array $a_modules = array(),
string $a_pattern =
"", array $a_topics = array()): array
183 $global_comments = $global_file_obj->getAllComments();
184 $local_values = self::_getValues($this->key, $a_modules, $a_topics, $a_pattern);
186 return array_intersect_key($local_values, $global_comments);
204 $global_values = $global_file_obj->getAllValues();
205 $local_values = self::_getValues($this->key);
207 return array_merge($global_values, $local_values);
224 $global_comments = $global_file_obj->getAllComments();
227 $local_remarks = self::_getRemarks($this->key,
true);
229 return array_merge($global_comments, $local_remarks);
238 public function importLanguageFile(
string $a_file,
string $a_mode_existing =
"keepnew"):
void 241 $ilDB = $DIC->database();
246 require_once
"./Services/Language/classes/class.ilLanguageFile.php";
248 if (!$import_file_obj->read()) {
249 $ilErr->raiseError($import_file_obj->getErrorMessage(),
$ilErr->MESSAGE);
252 switch ($a_mode_existing) {
271 $ilDB->manipulate(
"DELETE FROM lng_modules WHERE lang_key = " .
272 $ilDB->quote($this->key,
"text"));
282 foreach ($import_file_obj->getAllValues() as
$key => $value) {
283 if (!isset($to_keep[$key])) {
284 $to_save[
$key] = $value;
287 self::_saveValues($this->key, $to_save, $import_file_obj->getAllComments());
299 $ilDB = $DIC->database();
301 $q =
"SELECT DISTINCT module FROM lng_data WHERE " .
302 " lang_key = " .
$ilDB->quote($a_lang_key,
"text") .
" order by module";
303 $set =
$ilDB->query($q);
307 $modules[] = $rec[
"module"];
320 public static function _getRemarks(
string $a_lang_key,
bool $a_all_changed =
false): array
323 $ilDB = $DIC->database();
324 $lng = $DIC->language();
326 $q =
"SELECT module, identifier, remarks" 328 .
" WHERE lang_key = " .
$ilDB->quote($a_lang_key,
"text");
330 if ($a_all_changed) {
331 $q .=
" AND (remarks IS NOT NULL OR local_change IS NOT NULL)";
333 $q .=
" AND remarks IS NOT NULL";
336 $result =
$ilDB->query($q);
339 while ($row =
$ilDB->fetchAssoc($result)) {
340 $remarks[$row[
"module"] .
$lng->separator . $row[
"identifier"]] = $row[
"remarks"];
358 array $a_modules = array(),
359 array $a_topics = array(),
360 string $a_pattern =
'',
364 $ilDB = $DIC->database();
365 $lng = $DIC->language();
367 $q =
"SELECT * FROM lng_data WHERE" .
368 " lang_key = " .
$ilDB->quote($a_lang_key,
"text") .
" ";
370 if (is_array($a_modules) && count($a_modules) > 0) {
371 $q .=
" AND " .
$ilDB->in(
"module", $a_modules,
false,
"text");
373 if (is_array($a_topics) && count($a_topics) > 0) {
374 $q .=
" AND " .
$ilDB->in(
"identifier", $a_topics,
false,
"text");
377 $q .=
" AND " .
$ilDB->like(
"value",
"text",
"%" . $a_pattern .
"%");
379 if ($a_state ===
"changed") {
380 $q .=
" AND NOT local_change IS NULL ";
382 if ($a_state ===
"unchanged") {
383 $q .=
" AND local_change IS NULL ";
385 $q .=
" ORDER BY module, identifier";
387 $set =
$ilDB->query($q);
391 $values[$rec[
"module"] .
$lng->separator . $rec[
"identifier"]] = $rec[
"value"];
403 public static function _saveValues(
string $a_lang_key, array $a_values = array(), array $a_remarks = array()): void
406 $ilDB = $DIC->database();
407 $lng = $DIC->language();
409 if (!is_array($a_values)) {
413 $save_date = (
new DateTime())->format(
"Y-m-d H:i:s");
417 $file_values = $global_file_obj->getAllValues();
418 $file_comments = $global_file_obj->getAllComments();
419 $db_values = self::_getValues($a_lang_key);
420 $db_comments = self::_getRemarks($a_lang_key);
421 $global_values = array_merge($db_values, $file_values);
422 $global_comments = array_merge($db_comments, $file_comments);
425 foreach ($a_values as
$key => $value) {
428 if (count(
$keys) !== 2) {
432 list($module, $topic) =
$keys;
433 $save_array[$module][$topic] = $value;
435 $are_comments_set = array_key_exists(
$key, $global_comments) && array_key_exists(
$key, $a_remarks);
436 $are_changes_made = (isset($global_values[
$key]) ? $global_values[
$key] != $value :
true) || (isset($db_values[$key]) ? $db_values[
$key] != $value :
true);
437 if ($are_changes_made || ($are_comments_set ? $global_comments[$key] != $a_remarks[$key] : $are_comments_set)) {
438 $local_change = (isset($db_values[$key]) ? $db_values[
$key] == $value :
true) || (isset($global_values[$key]) ? $global_values[
$key] != $value :
true) ? $save_date : null;
445 $a_remarks[$key] ?? null
451 foreach ($save_array as $module => $entries) {
452 $set =
$ilDB->query(sprintf(
453 "SELECT * FROM lng_modules " .
454 "WHERE lang_key = %s AND module = %s",
455 $ilDB->quote($a_lang_key,
"text"),
456 $ilDB->quote($module,
"text")
458 $row =
$ilDB->fetchAssoc($set);
460 $arr = isset($row[
"lang_array"]) ? unserialize($row[
"lang_array"], [
"allowed_classes" =>
false]) :
"";
461 if (is_array($arr)) {
462 $entries = array_merge($arr, $entries);
464 ilObjLanguage::replaceLangModule($a_lang_key, $module, $entries);
467 require_once(
"class.ilCachedLanguage.php");
477 public static function _deleteValues(
string $a_lang_key, array $a_values = array()): void
480 $ilDB = $DIC->database();
481 $lng = $DIC->language();
483 if (!is_array($a_values)) {
486 $delete_array = array();
489 foreach ($a_values as
$key => $value) {
491 if (count(
$keys) === 2) {
494 $delete_array[$module][$topic] = $value;
501 foreach ($delete_array as $module => $entries) {
502 $set =
$ilDB->query(sprintf(
503 "SELECT * FROM lng_modules " .
504 "WHERE lang_key = %s AND module = %s",
505 $ilDB->quote($a_lang_key,
"text"),
506 $ilDB->quote($module,
"text")
508 $row =
$ilDB->fetchAssoc($set);
510 $arr = unserialize($row[
"lang_array"], [
"allowed_classes" =>
false]);
511 if (is_array($arr)) {
512 $entries = array_diff_key($arr, $entries);
514 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.
setDescription(string $desc)
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.
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.