120 $this->separator = $lng->separator;
121 $this->comment_separator = $lng->comment_separator;
123 $this->lang_file = $a_file;
124 $this->lang_key = $a_key;
125 $this->scope = $a_scope;
133 $this->params[
"module"] =
"language file";
134 $this->params[
"modulegroup"] =
"language";
136 if ($this->scope ==
"local")
138 $this->params[
"based_on"] =
"";
142 $this->params[
"author"] =
"";
143 $this->params[
"version"] =
"";
146 $this->params[
"il_server"] = ILIAS_HTTP_PATH;
148 $this->params[
"created"] =
"";
149 $this->params[
"created_by"] =
"";
161 $this->params = array();
162 $this->values = array();
163 $this->comments = array();
164 $this->error_message =
"";
166 $content = file($this->lang_file);
169 foreach ($content as $line_num => $line)
174 $this->header .= $line .
"\n";
177 if (trim($line) == $this->file_start)
185 $pos_par = strpos($line,
"* @");
187 if ($pos_par !==
false)
190 $pos_space = strpos($line,
" ", $pos_par);
191 $pos_tab = strpos($line,
"\t", $pos_par);
192 if ($pos_space !==
false and $pos_tab !==
false)
194 $pos_white = min($pos_space, $pos_tab);
196 elseif ($pos_space !==
false)
198 $pos_white = $pos_space;
200 elseif ($pos_tab !==
false)
202 $pos_white = $pos_tab;
210 $param = substr($line, $pos_par, $pos_white-$pos_par);
211 $value = trim(substr($line, $pos_white));
213 $this->params[$param] = $value;
221 $separated = explode($this->separator, trim($line));
224 if (count($separated) != 3)
226 $this->error_message =
227 $lng->txt(
"file_not_valid").
" "
228 .$lng->txt(
"err_in_line").
" ". $line_num .
". "
229 .$lng->txt(
"err_count_param");
234 $key = $separated[0].$this->separator.$separated[1];
235 $value = $separated[2];
238 $pos = strpos($value, $this->comment_separator);
241 $this->comments[$key]
242 = substr($value , $pos + strlen($this->comment_separator));
244 $value = substr($value , 0 , $pos);
246 $this->values[$key] = $value;
253 $this->error_message = $lng->txt(
"file_not_valid").
" ".$lng->txt(
"err_wrong_header");
267 public function write($a_header =
'')
269 $fp = fopen($this->lang_file,
"w");
270 fwrite($fp, $this->
build($a_header));
280 public function build($a_header =
'')
287 $content = $a_header;
292 $lang_name = $lng->txtlng(
'common',
'lang_'.$this->lang_key,
'en');
293 $this->params[
"module"] =
"language file ". $lang_name;
294 $this->params[
"created"] = date(
'Y-m-d H:i:s');
295 $this->params[
"created_by"] = $ilUser->getFullname().
" <".$ilUser->getEmail().
">";
298 $tpl =
new ilTemplate(
"tpl.lang_file_header.html",
true,
true,
"Services/Language");
301 $tabs = ceil((20 - 3 - strlen($name)) / 4);
302 $tabs = $tabs > 0 ? $tabs : 1;
304 $tpl->setCurrentBlock(
'param');
305 $tpl->setVariable(
'PAR_NAME', $name);
306 $tpl->setVariable(
'PAR_SPACE', str_repeat(
"\t", $tabs));
307 $tpl->setVariable(
'PAR_VALUE', $value);
308 $tpl->parseCurrentBlock();
310 $txt_scope = $lng->txtlng(
'administration',
'language_scope_'.$this->scope,
'en');
311 $tpl->setVariable(
'SCOPE', $txt_scope);
313 $content =
$tpl->get();
317 $add_newline = (substr($content, strlen($content)-1, 1) !=
"\n");
320 foreach ($this->values as $key => $value)
330 $content .= $key . $this->separator . $value;
332 if ($this->comments[$key])
334 $content .= $this->comment_separator . $this->comments[$key];
395 return $this->params[$a_name];
406 return $this->values[$a_module.$this->separator.$a_identifier];
417 return $this->comments[$a_module.$this->separator.$a_identifier];
427 $this->params[$a_name] = $a_value;
436 public function setValue($a_module, $a_identifier, $a_value)
438 $this->values[$a_module.$this->separator.$a_identifier] = $a_value;
447 $this->values = $a_values;
456 $this->comments = $a_comments;
466 public function setComment($a_module, $a_identifier, $a_value)
468 return $this->comments[$a_module.$this->separator.$a_identifier] = $a_comment;
480 if (!isset(self::$global_file_objects[$a_lang_key]))
483 $lng->lang_path .
"/ilias_" . $a_lang_key .
".lang",
484 $a_lang_key,
'global');
485 $file_object->read();
487 self::$global_file_objects[$a_lang_key] = $file_object;
490 return self::$global_file_objects[$a_lang_key];