ILIAS  Release_3_10_x_branch Revision 61812
 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 ()
 Write a language file.
 build ()
 Build and get the file content.
 getErrorMessage ()
 Get the error message of the last read/write operation.
 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.
 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 object.

Private Attributes

 $lang_file
 $lang_key
 $scope
 $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 103 of file class.ilLanguageFile.php.

References $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;
// 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 object.

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

Definition at line 384 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 ( )

Build and get the file content.

Returns
string language file content

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

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

Referenced by write().

{
global $ilUser, $lng;
// set default params
$lang_name = $lng->txtlng('common','lang_'.$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)
{
$tpl->setCurrentBlock('param');
$tpl->setVariable('PAR_NAME', $name);
$tpl->setVariable('PAR_VALUE', $value);
$tpl->parseCurrentBlock();
}
$txt_scope = $lng->txtlng('administration','language_scope_'.$this->scope,'en');
$tpl->setVariable('SCOPE', $txt_scope, 'en');
// build the content
$content = $tpl->get();
foreach ($this->getAllValues() as $key => $value)
{
$content .= $key . $this->separator . $value . "\n";
}
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 301 of file class.ilLanguageFile.php.

References $comments.

{
}
ilLanguageFile::getAllParams ( )

Get array of all parameters.

Returns
array name => value

Definition at line 283 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 292 of file class.ilLanguageFile.php.

References $values.

Referenced by build().

{
return $this->values;
}

+ Here is the caller graph for this function:

ilLanguageFile::getComment (   $a_module,
  $a_identifier 
)

Get a single comment.

Parameters
stringmodule name
stringindentifier
Returns
string value

Definition at line 333 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 274 of file class.ilLanguageFile.php.

References $error_message.

{
}
ilLanguageFile::getParam (   $a_name)

Get a single parameter.

Parameters
stringparameter name
Returns
string parameter value

Definition at line 311 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 322 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 139 of file class.ilLanguageFile.php.

References $lng.

{
global $lng;
$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)
{
// check header end
if (trim($line) == "<!-- language 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);
$pos_white = min($pos_space, $pos_tab);
$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::setAllValues (   $a_values)

Set all values.

Parameters
arraymodule.separator.identifier => value

Definition at line 363 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 374 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 343 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 354 of file class.ilLanguageFile.php.

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

Write a language file.

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

References build().

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

+ Here is the call graph for this function:

Field Documentation

ilLanguageFile::$comment_separator
private

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

ilLanguageFile::$comments = array()
private

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

Referenced by getAllComments().

ilLanguageFile::$error_message = ""
private

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

Referenced by getErrorMessage().

ilLanguageFile::$global_file_objects = array()
staticprivate

Created global file objects.

array

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

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 77 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 65 of file class.ilLanguageFile.php.

ilLanguageFile::$values = array()
private

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

Referenced by getAllValues().


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