ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilLanguageFile Class Reference

Class ilLanguageFile. More...

+ Collaboration diagram for ilLanguageFile:

Public Member Functions

 __construct ($a_file, $a_key="", $a_scope= 'global')
 Constructor.
 read ()
 Read a language file.
 write ($a_header= '')
 Write a language file.
 build ($a_header= '')
 Build and get the file content.
 getErrorMessage ()
 Get the error message of the last read/write operation.
 getHeader ()
 Get the header of the original file.
 getAllParams ()
 Get array of all parameters.
 getAllValues ()
 Get array of all values.
 getAllComments ()
 Get array of all comments.
 getParam ($a_name)
 Get a single parameter.
 getValue ($a_module, $a_identifier)
 Get a single value.
 getComment ($a_module, $a_identifier)
 Get a single comment.
 setParam ($a_name, $a_value)
 Set a parameter.
 setValue ($a_module, $a_identifier, $a_value)
 Set a single value.
 setAllValues ($a_values)
 Set all values.
 setAllComments ($a_comments)
 Set all comments.
 setComment ($a_module, $a_identifier, $a_value)
 Set a single comment.

Static Public Member Functions

static _getGlobalLanguageFile ($a_lang_key)
 Read and get a global language file as a singleton object.

Private Attributes

 $lang_file
 $lang_key
 $scope
 $header
 $file_start = "<!-- language file start -->"
 $separator
 $comment_separator
 $params = array()
 $values = array()
 $comments = array()
 $error_message = ""

Static Private Attributes

static $global_file_objects = array()
 Created global file objects.

Detailed Description

Class ilLanguageFile.

Provides methods for working with language files: read, check and write content, comments and parameters

Author
Fred Neumann fred..nosp@m.neum.nosp@m.ann@f.nosp@m.im.u.nosp@m.ni-er.nosp@m.lang.nosp@m.en.de
Version
$Id$

Definition at line 35 of file class.ilLanguageFile.php.

Constructor & Destructor Documentation

ilLanguageFile::__construct (   $a_file,
  $a_key = "",
  $a_scope = 'global' 
)

Constructor.

Parameters
stringlanguage file path and name
string(optional) language key
string(optional) scope ('global', 'local' or 'unchanged')

Definition at line 117 of file class.ilLanguageFile.php.

References $file_start, $lng, and ILIAS_VERSION.

{
global $lng;
$this->separator = $lng->separator;
$this->comment_separator = $lng->comment_separator;
$this->lang_file = $a_file;
$this->lang_key = $a_key;
$this->scope = $a_scope;
// initialize the header of a blank file
$this->header = $file_start;
// Set the default parameters to be written in a new file.
// This ensures the correct order of parameters
$this->params["module"] = "language file";
$this->params["modulegroup"] = "language";
if ($this->scope == "local")
{
$this->params["based_on"] = "";
}
else
{
$this->params["author"] = "";
$this->params["version"] = "";
}
$this->params["il_server"] = ILIAS_HTTP_PATH;
$this->params["il_version"] = ILIAS_VERSION;
$this->params["created"] = "";
$this->params["created_by"] = "";
}

Member Function Documentation

static ilLanguageFile::_getGlobalLanguageFile (   $a_lang_key)
static

Read and get a global language file as a singleton object.

Parameters
stringlanguage key
Returns
object language file object (with contents)

Definition at line 477 of file class.ilLanguageFile.php.

References $lng.

Referenced by ilObjLanguageExt\_saveValues(), and ilObjLanguageExt\getGlobalLanguageFile().

{
global $lng;
if (!isset(self::$global_file_objects[$a_lang_key]))
{
$file_object = new ilLanguageFile(
$lng->lang_path . "/ilias_" . $a_lang_key . ".lang",
$a_lang_key, 'global');
$file_object->read();
self::$global_file_objects[$a_lang_key] = $file_object;
}
return self::$global_file_objects[$a_lang_key];
}

+ Here is the caller graph for this function:

ilLanguageFile::build (   $a_header = '')

Build and get the file content.

Parameters
string(optional) fixed header for the new file
Returns
string language file content

Definition at line 280 of file class.ilLanguageFile.php.

References $ilUser, $lng, $tpl, and getAllParams().

Referenced by write().

{
global $ilUser, $lng;
if ($a_header)
{
// take the given header
$content = $a_header;
}
else
{
// set default params
$lng->loadLanguageModule('meta');
$lang_name = $lng->txtlng('meta','meta_l_'.$this->lang_key,'en');
$this->params["module"] = "language file ". $lang_name;
$this->params["created"] = date('Y-m-d H:i:s');
$this->params["created_by"] = $ilUser->getFullname()." <".$ilUser->getEmail().">";
// build the header
$tpl = new ilTemplate("tpl.lang_file_header.html", true,true, "Services/Language");
foreach ($this->getAllParams() as $name => $value)
{
$tabs = ceil((20 - 3 - strlen($name)) / 4);
$tabs = $tabs > 0 ? $tabs : 1;
$tpl->setCurrentBlock('param');
$tpl->setVariable('PAR_NAME', $name);
$tpl->setVariable('PAR_SPACE', str_repeat("\t", $tabs));
$tpl->setVariable('PAR_VALUE', $value);
$tpl->parseCurrentBlock();
}
$txt_scope = $lng->txtlng('administration','language_scope_'.$this->scope, 'en');
$tpl->setVariable('SCOPE', $txt_scope);
$content = $tpl->get();
}
// fault tolerant check for adding newline
$add_newline = (substr($content, strlen($content)-1, 1) != "\n");
// build the content
foreach ($this->values as $key => $value)
{
// add the newline before the line!
// a valid lang file should not have a newline at the end!
if ($add_newline)
{
$content .= "\n";
}
$add_newline = true;
$content .= $key . $this->separator . $value;
if ($this->comments[$key])
{
$content .= $this->comment_separator . $this->comments[$key];
}
}
return $content;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilLanguageFile::getAllComments ( )

Get array of all comments.

Returns
array module.separator.identifier => comment

Definition at line 384 of file class.ilLanguageFile.php.

References $comments.

{
}
ilLanguageFile::getAllParams ( )

Get array of all parameters.

Returns
array name => value

Definition at line 366 of file class.ilLanguageFile.php.

References $params.

Referenced by build().

{
return $this->params;
}

+ Here is the caller graph for this function:

ilLanguageFile::getAllValues ( )

Get array of all values.

Returns
array module.separator.identifier => value

Definition at line 375 of file class.ilLanguageFile.php.

References $values.

{
return $this->values;
}
ilLanguageFile::getComment (   $a_module,
  $a_identifier 
)

Get a single comment.

Parameters
stringmodule name
stringindentifier
Returns
string value

Definition at line 416 of file class.ilLanguageFile.php.

{
return $this->comments[$a_module.$this->separator.$a_identifier];
}
ilLanguageFile::getErrorMessage ( )

Get the error message of the last read/write operation.

Returns
string error message

Definition at line 346 of file class.ilLanguageFile.php.

References $error_message.

{
}
ilLanguageFile::getHeader ( )

Get the header of the original file.

Returns
string

Definition at line 356 of file class.ilLanguageFile.php.

References $header.

{
return $this->header;
}
ilLanguageFile::getParam (   $a_name)

Get a single parameter.

Parameters
stringparameter name
Returns
string parameter value

Definition at line 394 of file class.ilLanguageFile.php.

{
return $this->params[$a_name];
}
ilLanguageFile::getValue (   $a_module,
  $a_identifier 
)

Get a single value.

Parameters
stringmodule name
stringindentifier
Returns
string value

Definition at line 405 of file class.ilLanguageFile.php.

{
return $this->values[$a_module.$this->separator.$a_identifier];
}
ilLanguageFile::read ( )

Read a language file.

Returns
boolean reading successful

Definition at line 156 of file class.ilLanguageFile.php.

References $lng.

{
global $lng;
$this->header = '';
$this->params = array();
$this->values = array();
$this->comments = array();
$this->error_message = "";
$content = file($this->lang_file);
$in_header = true;
foreach ($content as $line_num => $line)
{
if ($in_header)
{
// store the header line
$this->header .= $line . "\n";
// check header end
if (trim($line) == $this->file_start)
{
$in_header = false;
continue;
}
else
{
// get header params
$pos_par = strpos($line, "* @");
if ($pos_par !== false)
{
$pos_par += 3;
$pos_space = strpos($line, " ", $pos_par);
$pos_tab = strpos($line, "\t", $pos_par);
if ($pos_space !== false and $pos_tab !== false)
{
$pos_white = min($pos_space, $pos_tab);
}
elseif ($pos_space !== false)
{
$pos_white = $pos_space;
}
elseif ($pos_tab !== false)
{
$pos_white = $pos_tab;
}
else
{
$pos_white = false;
}
if ($pos_white)
{
$param = substr($line, $pos_par, $pos_white-$pos_par);
$value = trim(substr($line, $pos_white));
$this->params[$param] = $value;
}
}
}
}
else
{
// separate the lang file entry
$separated = explode($this->separator, trim($line));
// not a valid line with module, identifier and value?
if (count($separated) != 3)
{
$this->error_message =
$lng->txt("file_not_valid"). " "
.$lng->txt("err_in_line")." ". $line_num . ". "
.$lng->txt("err_count_param");
return false;
}
else
{
$key = $separated[0].$this->separator.$separated[1];
$value = $separated[2];
// cut off comment
$pos = strpos($value, $this->comment_separator);
if ($pos !== false)
{
$this->comments[$key]
= substr($value , $pos + strlen($this->comment_separator));
$value = substr($value , 0 , $pos);
}
$this->values[$key] = $value;
}
}
}
// still in header after parsing the whole file?
if ($in_header)
{
$this->error_message = $lng->txt("file_not_valid")." ".$lng->txt("err_wrong_header");
return false;
}
else
{
return true;
}
}
ilLanguageFile::setAllComments (   $a_comments)

Set all comments.

Parameters
arraymodule.separator.identifier => comment

Definition at line 455 of file class.ilLanguageFile.php.

{
$this->comments = $a_comments;
}
ilLanguageFile::setAllValues (   $a_values)

Set all values.

Parameters
arraymodule.separator.identifier => value

Definition at line 446 of file class.ilLanguageFile.php.

{
$this->values = $a_values;
}
ilLanguageFile::setComment (   $a_module,
  $a_identifier,
  $a_value 
)

Set a single comment.

Parameters
stringmodule name
stringindentifier
stringcomment

Definition at line 467 of file class.ilLanguageFile.php.

{
return $this->comments[$a_module.$this->separator.$a_identifier] = $a_comment;
}
ilLanguageFile::setParam (   $a_name,
  $a_value 
)

Set a parameter.

Parameters
stringparameter name
stringparameter value

Definition at line 426 of file class.ilLanguageFile.php.

{
$this->params[$a_name] = $a_value;
}
ilLanguageFile::setValue (   $a_module,
  $a_identifier,
  $a_value 
)

Set a single value.

Parameters
stringmodule name
stringindentifier
stringvalue

Definition at line 437 of file class.ilLanguageFile.php.

{
$this->values[$a_module.$this->separator.$a_identifier] = $a_value;
}
ilLanguageFile::write (   $a_header = '')

Write a language file.

Parameters
string(optional) fixed header for the new file

Definition at line 267 of file class.ilLanguageFile.php.

References build().

{
$fp = fopen($this->lang_file, "w");
fwrite($fp, $this->build($a_header));
fclose($fp);
}

+ Here is the call graph for this function:

Field Documentation

ilLanguageFile::$comment_separator
private

Definition at line 85 of file class.ilLanguageFile.php.

ilLanguageFile::$comments = array()
private

Definition at line 103 of file class.ilLanguageFile.php.

Referenced by getAllComments().

ilLanguageFile::$error_message = ""
private

Definition at line 109 of file class.ilLanguageFile.php.

Referenced by getErrorMessage().

ilLanguageFile::$file_start = "<!-- language file start -->"
private

Definition at line 72 of file class.ilLanguageFile.php.

Referenced by __construct().

ilLanguageFile::$global_file_objects = array()
staticprivate

Created global file objects.

array

Definition at line 41 of file class.ilLanguageFile.php.

ilLanguageFile::$header
private

Definition at line 66 of file class.ilLanguageFile.php.

Referenced by getHeader().

ilLanguageFile::$lang_file
private

Definition at line 47 of file class.ilLanguageFile.php.

ilLanguageFile::$lang_key
private

Definition at line 53 of file class.ilLanguageFile.php.

ilLanguageFile::$params = array()
private

Definition at line 91 of file class.ilLanguageFile.php.

Referenced by getAllParams().

ilLanguageFile::$scope
private

Definition at line 59 of file class.ilLanguageFile.php.

ilLanguageFile::$separator
private

Definition at line 79 of file class.ilLanguageFile.php.

ilLanguageFile::$values = array()
private

Definition at line 97 of file class.ilLanguageFile.php.

Referenced by getAllValues().


The documentation for this class was generated from the following file: