19 declare(strict_types=1);
    53     public function __construct(
string $a_file, 
string $a_key = 
"", 
string $a_scope = 
"global")
    56         $lng = $DIC->language();
    58         $this->separator = 
$lng->separator;
    59         $this->comment_separator = 
$lng->comment_separator;
    61         $this->lang_file = $a_file;
    62         $this->lang_key = $a_key;
    63         $this->scope = $a_scope;
    71         $this->params[
"module"] = 
"language file";
    72         $this->params[
"modulegroup"] = 
"language";
    74         if ($this->scope === 
"local") {
    75             $this->params[
"based_on"] = 
"";
    77             $this->params[
"author"] = 
"";
    78             $this->params[
"version"] = 
"";
    81         $this->params[
"il_server"] = ILIAS_HTTP_PATH;
    83         $this->params[
"created"] = 
"";
    84         $this->params[
"created_by"] = 
"";
    91     public function read(): bool
    94         $lng = $DIC->language();
    97         $this->params = array();
    98         $this->values = array();
    99         $this->comments = array();
   100         $this->error_message = 
"";
   102         $content = file($this->lang_file);
   105         foreach ($content as $line_num => $line) {
   108                 $this->
header .= $line . 
"\n";
   111                 if (trim($line) === $this->file_start) {
   115                     $pos_par = strpos($line, 
"* @");
   117                     if (strpos($line, 
"* @") !== 
false) {
   119                         $pos_space = strpos($line, 
" ", $pos_par);
   120                         $pos_tab = strpos($line, 
"\t", $pos_par);
   121                         if ($pos_space !== 
false && $pos_tab !== 
false) {
   122                             $pos_white = min($pos_space, $pos_tab);
   123                         } elseif ($pos_space !== 
false) {
   124                             $pos_white = $pos_space;
   125                         } elseif ($pos_tab !== 
false) {
   126                             $pos_white = $pos_tab;
   131                             $param = substr($line, $pos_par, $pos_white - $pos_par);
   132                             $value = trim(substr($line, $pos_white));
   134                             $this->params[
$param] = $value;
   140                 $separated = explode($this->separator, trim($line));
   143                 if (count($separated) !== 3) {
   144                     $this->error_message =
   145                             $lng->txt(
"file_not_valid") . 
" "   146                             . 
$lng->txt(
"err_in_line") . 
" " . $line_num . 
". "   147                             . 
$lng->txt(
"err_count_param");
   150                     $key = $separated[0] . $this->separator . $separated[1];
   151                     $value = $separated[2];
   154                     $pos = strpos($value, $this->comment_separator);
   155                     if ($pos !== 
false) {
   156                         $this->comments[
$key]
   157                             = substr($value, $pos + strlen($this->comment_separator));
   159                         $value = substr($value, 0, $pos);
   161                     $this->values[
$key] = $value;
   167             $this->error_message = 
$lng->txt(
"file_not_valid") . 
" " . 
$lng->txt(
"err_wrong_header");
   179     public function write(
string $a_header = 
""): void
   181         $fp = fopen($this->lang_file, 
'wb');
   182         fwrite($fp, $this->
build($a_header));
   191     public function build(
string $a_header = 
''): string
   194         $ilUser = $DIC->user();
   195         $lng = $DIC->language();
   199             $content = $a_header;
   202             $lng->loadLanguageModule(
"meta");
   203             $lang_name = 
$lng->txtlng(
"meta", 
"meta_l_" . $this->lang_key, 
"en");
   204             $this->params[
"module"] = 
"language file " . $lang_name;
   205             $this->params[
"created"] = date(
"Y-m-d H:i:s");
   206             $this->params[
"created_by"] = $ilUser->getFullname() . 
" <" . $ilUser->getEmail() . 
">";
   209             $tpl = 
new ilTemplate(
"tpl.lang_file_header.html", 
true, 
true, 
"Services/Language");
   211                 $tabs = intval(ceil((20 - 3 - strlen($name)) / 4));
   212                 $tabs = $tabs > 0 ? $tabs : 1;
   214                 $tpl->setCurrentBlock(
"param");
   215                 $tpl->setVariable(
"PAR_NAME", $name);
   216                 $tpl->setVariable(
"PAR_SPACE", str_repeat(
"\t", $tabs));
   217                 $tpl->setVariable(
"PAR_VALUE", $value);
   218                 $tpl->parseCurrentBlock();
   220             $txt_scope = 
$lng->txtlng(
"administration", 
"language_scope_" . $this->scope, 
"en");
   221             $tpl->setVariable(
"SCOPE", $txt_scope);
   223             $content = $tpl->get();
   227         $add_newline = (substr($content, strlen($content) - 1, 1) !== 
"\n");
   230         foreach ($this->values as 
$key => $value) {
   238             $content .= 
$key . $this->separator . $value;
   240             if (isset($this->comments[
$key])) {
   241                 $content .= $this->comment_separator . $this->comments[
$key];
   299         return $this->params[$a_name] ?? 
'';
   307     public function getValue(
string $a_module, 
string $a_identifier): string
   309         return $this->values[$a_module . $this->separator . $a_identifier];
   317     public function getComment(
string $a_module, 
string $a_identifier): string
   319         return $this->comments[$a_module . $this->separator . $a_identifier];
   327     public function setParam(
string $a_name, 
string $a_value): void
   329         $this->params[$a_name] = $a_value;
   338     public function setValue(
string $a_module, 
string $a_identifier, 
string $a_value): void
   340         $this->values[$a_module . $this->separator . $a_identifier] = $a_value;
   349         $this->values = $a_values;
   358         $this->comments = $a_comments;
   368     public function setComment(
string $a_module, 
string $a_identifier, 
string $a_comment): string
   370         return $this->comments[$a_module . $this->separator . $a_identifier] = $a_comment;
   381         $lng = $DIC->language();
   383         if (!isset(self::$global_file_objects[$a_lang_key])) {
   385                 $lng->lang_path . 
"/ilias_" . $a_lang_key . 
".lang",
   389             $file_object->read();
   391             self::$global_file_objects[$a_lang_key] = $file_object;
   394         return self::$global_file_objects[$a_lang_key];
 setComment(string $a_module, string $a_identifier, string $a_comment)
Set a single comment $a_module module name $a_identifier indentifier $a_comment comment. 
 
string $comment_separator
 
getErrorMessage()
Get the error message of the last read/write operation. 
 
setValue(string $a_module, string $a_identifier, string $a_value)
Set a single value $a_module module name $a_identifier indentifier $a_value value. 
 
setParam(string $a_name, string $a_value)
Set a parameter $a_name parameter name $a_value parameter value. 
 
write(string $a_header="")
Write a language file. 
 
setAllValues(array $a_values)
Set all values $a_values [module.separator.identifier => value]. 
 
getAllComments()
Get array of all comments Return array [module.separator.identifier => comment]. 
 
__construct(string $a_file, string $a_key="", string $a_scope="global")
Constructor $a_file language file path and name $a_key (optional) language key $a_scope (optional) sc...
 
getComment(string $a_module, string $a_identifier)
Get a single comment $a_module module name $a_identifier indentifier. 
 
getParam(string $a_name)
Get a single parameter $a_name parameter name. 
 
getValue(string $a_module, string $a_identifier)
Get a single value $a_module module name $a_identifier indentifier. 
 
setAllComments(array $a_comments)
Set all comments $a_comments [module.separator.identifier => comment]. 
 
getAllParams()
Get array of all parameters Return array [name => value]. 
 
getHeader()
Get the header of the original file. 
 
static array $global_file_objects
 
static _getGlobalLanguageFile(string $a_lang_key)
Read and get a global language file as a singleton object $a_lang_key language key. 
 
build(string $a_header='')
Build and get the file content. 
 
getAllValues()
Get array of all values Return array [module.separator.identifier => value]. 
 
read()
Read a language file Return true, if reading successful.