19 declare(strict_types=1);
    50     public function __construct(
int $a_id = 0, 
bool $a_call_by_reference = 
false)
    53         $lng = $DIC->language();
    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;
   114         if ($this->key == $this->lang_default) {
   126         if ($this->key == $this->lang_user) {
   140         if (strpos($this->
getStatus(), 
"installed") === 0) {
   155         if (substr($this->
getStatus(), 10) === 
"local") {
   171             if (
$scope === 
"global") {
   174                 $scopeExtension = 
"." . 
$scope;
   182                     $this->
flush(
"keep_local");
   191                     $newDesc = 
"installed";
   192                 } elseif (
$scope === 
"local") {
   193                     $newDesc = 
"installed_local";
   211         if ((strpos($this->status, 
"installed") === 0) && ($this->key != $this->lang_default) && ($this->key != $this->lang_user)) {
   230             $this->
flush(
"keep_local");
   255         $refreshed = array();
   257         foreach ($languages as 
$lang) {
   259             if ($langObj->refresh()) {
   260                 $refreshed[] = $langObj->getKey();
   265         self::refreshPlugins($refreshed);
   277         $component_repository = $DIC[
"component.repository"];
   278         foreach ($component_repository->getPlugins() as 
$plugin) {
   283             $handler->updateLanguages($a_lang_keys);
   292     public static function _deleteLangData(
string $a_lang_key, 
bool $a_keep_local_change = 
false): void
   295         $ilDB = $DIC->database();
   297         if (!$a_keep_local_change) {
   298             $ilDB->manipulate(
"DELETE FROM lng_data WHERE lang_key = " .
   299                 $ilDB->quote($a_lang_key, 
"text"));
   301             $ilDB->manipulate(
"DELETE FROM lng_data WHERE lang_key = " .
   302                 $ilDB->quote($a_lang_key, 
"text") .
   303                 " AND local_change IS NULL");
   311     public function flush(
string $a_mode = 
"all"): void
   314         $ilDB = $DIC->database();
   316         self::_deleteLangData($this->key, ($a_mode === 
"keep_local"));
   318         if ($a_mode === 
"all") {
   319             $ilDB->manipulate(
"DELETE FROM lng_modules WHERE lang_key = " .
   320                 $ilDB->quote($this->key, 
"text"));
   331     public function getLocalChanges(
string $a_min_date = 
"", 
string $a_max_date = 
""): array
   334         $ilDB = $DIC->database();
   336         if ($a_min_date === 
"") {
   337             $a_min_date = 
"1980-01-01 00:00:00";
   339         if ($a_max_date === 
"") {
   340             $a_max_date = 
"2200-01-01 00:00:00";
   344             "SELECT * FROM lng_data WHERE lang_key = %s " .
   345             "AND local_change >= %s AND local_change <= %s",
   346             $ilDB->quote($this->key, 
"text"),
   347             $ilDB->quote($a_min_date, 
"timestamp"),
   348             $ilDB->quote($a_max_date, 
"timestamp")
   354             $changes[$row[
"module"]][$row[
"identifier"]] = $row[
"value"];
   368         $ilDB = $DIC->database();
   371             "SELECT MAX(local_change) last_change FROM lng_data " .
   372                     "WHERE lang_key = %s AND local_change IS NOT NULL",
   373             $ilDB->quote($a_key, 
"text")
   378             return (
string) $row[
"last_change"];
   394         $ilDB = $DIC->database();
   397         $result = 
$ilDB->queryF(
   398             "SELECT * FROM lng_data WHERE lang_key = %s AND module = %s AND local_change IS NOT NULL",
   399             array(
"text", 
"text"),
   400             array($a_key, $a_module)
   403         while ($row = 
$ilDB->fetchAssoc($result)) {
   404             $changes[$row[
"identifier"]] = $row[
"value"];
   418         $ilDB = $DIC->database();
   419         $scopeExtension = 
"";
   421             if (
$scope === 
"global") {
   424                 $scopeExtension = 
"." . 
$scope;
   433         $lang_file = 
$path . 
"/ilias_" . $this->key . 
".lang" . $scopeExtension;
   435         if (is_file($lang_file)) {
   437             if ($content = self::cut_header(file($lang_file))) {
   438                 $local_changes = null;
   442                 } elseif (
$scope === 
"local") {
   445                     $min_date = date(
"Y-m-d H:i:s", filemtime($lang_file));
   449                 $lang_array = $dbAccess->insertLangEntries($lang_file);
   450                 $dbAccess->replaceLangModules($lang_array);
   458     final public static function replaceLangModule(
string $a_key, 
string $a_module, array $a_array): 
void   461         $ilDB = $DIC->database();
   466         $ilDB->manipulate(sprintf(
   467             "DELETE FROM lng_modules WHERE lang_key = %s AND module = %s",
   468             $ilDB->quote($a_key, 
"text"),
   469             $ilDB->quote($a_module, 
"text")
   476         $ilDB->insert(
"lng_modules", array(
   477             "lang_key" => array(
"text", $a_key),
   478             "module" => array(
"text", $a_module),
   479             "lang_array" => array(
"clob", serialize($a_array))
   484         $result = 
$ilDB->queryF(
   485             "SELECT lang_array FROM lng_modules WHERE lang_key = %s AND module = %s",
   486             array(
"text",
"text"),
   487             array($a_key, $a_module)
   489         $row = 
$ilDB->fetchAssoc($result);
   491         $unserialied = unserialize($row[
"lang_array"], [
"allowed_classes" => 
false]);
   492         if (!is_array($unserialied)) {
   496                 "Data for module '" . $a_module . 
"' of  language '" . $a_key . 
"' is not correctly saved. " .
   497                 "Please check the collation of your database tables lng_data and lng_modules. It must be utf8_unicode_ci.",
   508         string $a_identifier,
   511         string $a_local_change = null,
   512         string $a_remarks = null
   515         $ilDB = $DIC->database();
   520         if (is_string($a_remarks) && $a_remarks !== 
'') {
   521             $a_remarks = substr($a_remarks, 0, 250);
   524         if ($a_remarks === 
'') {
   528         if ($a_value === 
"") {
   531             $a_value = substr($a_value, 0, 4000);
   537                 "module" => array(
"text",$a_module),
   538                 "identifier" => array(
"text",$a_identifier),
   539                 "lang_key" => array(
"text",$a_lang_key)
   542                 "value" => array(
"text",$a_value),
   543                 "local_change" => array(
"timestamp",$a_local_change),
   544                 "remarks" => array(
"text", $a_remarks)
   555         string $a_identifier,
   558         string $a_local_change = null,
   559         string $a_remarks = null
   562         $ilDB = $DIC->database();
   564         if (is_string($a_remarks) && $a_remarks !== 
'') {
   565             $a_remarks = substr($a_remarks, 0, 250);
   568         if ($a_remarks === 
'') {
   572         if ($a_value === 
"") {
   575             $a_value = substr($a_value, 0, 4000);
   578         $ilDB->manipulate(sprintf(
   580             "SET value = %s, local_change = %s, remarks = %s " .
   581             "WHERE module = %s AND identifier = %s AND lang_key = %s ",
   582             $ilDB->quote($a_value, 
"text"),
   583             $ilDB->quote($a_local_change, 
"timestamp"),
   584             $ilDB->quote($a_remarks, 
"text"),
   585             $ilDB->quote($a_module, 
"text"),
   586             $ilDB->quote($a_identifier, 
"text"),
   587             $ilDB->quote($a_lang_key, 
"text")
   595     final public static function deleteLangEntry(
string $a_module, 
string $a_identifier, 
string $a_lang_key): bool
   598         $ilDB = $DIC->database();
   600         $ilDB->manipulate(sprintf(
   601             "DELETE FROM lng_data " .
   602             "WHERE module = %s AND identifier = %s AND lang_key = %s ",
   603             $ilDB->quote($a_module, 
"text"),
   604             $ilDB->quote($a_identifier, 
"text"),
   605             $ilDB->quote($a_lang_key, 
"text")
   621         $ilDB = $DIC->database();
   623         $query = 
"UPDATE usr_pref SET " .
   624                 "value = " . 
$ilDB->quote($this->lang_default, 
"text") . 
" " .
   625                 "WHERE keyword = " . 
$ilDB->quote(
'language', 
"text") . 
" " .
   626                 "AND value = " . 
$ilDB->quote($lang_key, 
"text");
   627         $ilDB->manipulate($query);
   641         foreach ($content as $key => $val) {
   642             if (trim($val) === 
"<!-- language file start -->") {
   643                 return array_slice($content, $key + 1);
   673         include_once 
"./Services/Utilities/classes/class.ilStr.php";
   674         $scopeExtension = 
"";
   676             if (
$scope === 
"global") {
   679                 $scopeExtension = 
"." . 
$scope;
   691         if (!is_dir(
$path)) {
   692             $this->
ilias->raiseError(
"Directory not found: " . 
$path, $this->
ilias->error_obj->MESSAGE);
   698         $lang_file = 
"ilias_" . $this->key . 
".lang" . $scopeExtension;
   701         if (!is_file($lang_file)) {
   702             $this->
ilias->raiseError(
"File not found: " . $lang_file, $this->
ilias->error_obj->MESSAGE);
   706         $content = self::cut_header(file($lang_file));
   707         if ($content === 
false) {
   708             $this->
ilias->raiseError(
"Wrong Header in " . $lang_file, $this->
ilias->error_obj->MESSAGE);
   714         foreach ($content as $key => $val) {
   715             $separated = explode($this->separator, trim($val));
   716             $num = count($separated);
   720                 $this->
ilias->raiseError(
"Wrong parameter count in " . $lang_file . 
" in line $line (Value: $val)! Please check your language file!", $this->
ilias->error_obj->MESSAGE);
   723                 $this->
ilias->raiseError(
"Non UTF8 character found in " . $lang_file . 
" in line $line (Value: $val)! Please check your language file!", $this->
ilias->error_obj->MESSAGE);
   739         $ilDB = $DIC->database();
   740         $lng = $DIC->language();
   742         $set = 
$ilDB->query(
"SELECT COUNT(*) cnt FROM usr_data ud JOIN usr_pref up" .
   743             " ON ud.usr_id = up.usr_id " .
   744             " WHERE up.value = " . 
$ilDB->quote($a_lang, 
"text") .
   745             " AND up.keyword = " . 
$ilDB->quote(
"language", 
"text"));
   746         $rec = 
$ilDB->fetchAssoc($set);
   749         if ($a_lang == 
$lng->lang_default) {
   750             $set2 = 
$ilDB->query(
"SELECT COUNT(*) cnt FROM usr_data ud LEFT JOIN usr_pref up" .
   751                 " ON (ud.usr_id = up.usr_id AND up.keyword = " . 
$ilDB->quote(
"language", 
"text") . 
")" .
   752                 " WHERE up.value IS NULL ");
   753             $rec2 = 
$ilDB->fetchAssoc($set2);
   756         return (
int) $rec[
"cnt"] + (
int) ($rec2[
"cnt"] ?? 0);
 insert(string $scope="")
insert language data from file into database 
 
optimizeData()
optimizes the db-table langdata 
 
static _deleteLangData(string $a_lang_key, bool $a_keep_local_change=false)
Delete languge data $a_lang_key lang key. 
 
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...
 
string $separator
separator of module, comment separator, identifier & values in language files 
 
static getInstalledLanguages()
Get the language objects of the installed languages. 
 
static countUsers(string $a_lang)
Count number of users that use a language. 
 
isInstalled()
Check language object status, and return true if language is installed. 
 
static _getObjectsByType(string $obj_type="", int $owner=null)
 
getStatus()
get language status 
 
uninstall()
uninstall current language 
 
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. 
 
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...
 
isSystemLanguage()
check if language is system language 
 
resetUserLanguage(string $lang_key)
search ILIAS for users which have selected '$lang_key' as their prefered language and reset them to d...
 
install(string $scope="")
install current language 
 
static isUtf8(string $a_str)
Check whether string is utf-8. 
 
refresh()
refresh current language 
 
header include for all ilias files. 
 
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. 
 
string $comment_separator
 
check(string $scope="")
Validate the logical structure of a lang file. 
 
flush(string $a_mode="all")
remove language data from database $a_mode "all" or "keep_local" 
 
static refreshAll()
Refresh all installed languages. 
 
isLocal()
Check language object status, and return true if a local language file is installed. 
 
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...
 
static cut_header(array $content)
remove lang-file haeder information from '$content' This function seeks for a special keyword where t...
 
__construct(int $a_id=0, bool $a_call_by_reference=false)
Constructor. 
 
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" ...
 
setDescription(string $description)
 
static deleteLangEntry(string $a_module, string $a_identifier, string $a_lang_key)
Delete lang entry.