Public Member Functions | Data Fields

ilObjLanguageExt Class Reference

Inheritance diagram for ilObjLanguageExt:
Collaboration diagram for ilObjLanguageExt:

Public Member Functions

 ilObjLanguageExt ($a_id=0, $a_call_by_reference=false)
 Constructor.
 setLocal ($a_local=true)
 Set the local status of the language.
 getLongDescription ()
 Get the full language description.
 getLangPath ()
 Get the language files path.
 getCustLangPath ()
 Get the customized language files path.
 getAllTranslations ($a_modules=array(), $a_pattern= '')
 Get all translation entries from the database.
 getChangedTranslations ($a_modules=array(), $a_pattern= '')
 Get only the changed translation entries from the database which differ from the original language file.
 getUnchangedTranslations ($a_modules=array(), $a_pattern= '')
 Get only the unchanged translation entries from the database which are equal to the original language file.
 getCommentedTranslations ($a_modules=array(), $a_pattern= '')
 Get all translation entries from the database for wich the original language file has a comment.
 getLangFileContent ()
 Get the whole language file content The language file has to be read first.
 getLangFileComments ()
 Get all language file comments The language file has to be read first.
 getLangFileParam ($a_param)
 Get a parameter value from the original language file header.
 getLangFileValue ($a_module, $a_topic)
 Get the value of a single language file entry.
 importLanguageFile ($a_file, $a_mode_existing= 'keepnew')
 Import a language file into the ilias database.
 readLanguageFile ($a_lang_file= '')
 Read the language file content and parameters into class arrays.
 _getModules ($a_lang_key)
 Get al modules of a language.
 _getTranslations ($a_lang_key, $a_modules=array(), $a_topics=array(), $a_pattern= '')
 Get the translations of specified topics.
 _saveTranslations ($a_lang_key, $a_translations=array())
 Save a set of translation in the database.

Data Fields

 $lang_file_param = array()
 $lang_file_content = array()
 $lang_file_comments = array()

Detailed Description

Definition at line 34 of file class.ilObjLanguageExt.php.


Member Function Documentation

ilObjLanguageExt::_getModules ( a_lang_key  ) 

Get al modules of a language.

static

Parameters:
string language key
Returns:
array list of modules

Definition at line 392 of file class.ilObjLanguageExt.php.

        {
                global $ilDB;
                
                $q = "SELECT DISTINCT module FROM lng_data WHERE ".
                        " lang_key = ".$ilDB->quote($a_lang_key).
                        " order by module";
                $set = $ilDB->query($q);

                while ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
                {
                        $modules[] = $rec["module"];
                }
                return $modules;
        }

ilObjLanguageExt::_getTranslations ( a_lang_key,
a_modules = array(),
a_topics = array(),
a_pattern = '' 
)

Get the translations of specified topics.

static

Parameters:
string language key
array list of modules
array list of topics
array search pattern
Returns:
array "module#:#topic" => translation

Definition at line 418 of file class.ilObjLanguageExt.php.

References ilObject::$lng.

Referenced by getAllTranslations(), getChangedTranslations(), getCommentedTranslations(), and getUnchangedTranslations().

        {
                global $ilDB, $lng;

                if (is_array($a_modules))
                {
                        for ($i = 0; $i < count($a_modules); $i++)
                        {
                                $a_modules[$i] = $ilDB->quote($a_modules[$i]);
                        }
            $modules_list = implode(',', $a_modules);
                }
                if (is_array($a_topics))
                {
                        for ($i = 0; $i < count($a_topics); $i++)
                        {
                                $a_topics[$i] = $ilDB->quote($a_topics[$i]);
                        }
                        $topics_list = implode(',', $a_topics);
                }

                $q = "SELECT * FROM lng_data WHERE".
                        " lang_key =".$ilDB->quote($a_lang_key);
                if ($modules_list)
                {
                        $q .= " AND module in (". $modules_list. ")";
                }
                if ($topics_list)
                {
                        $q .= " AND identifier in (". $topics_list. ")";
                }
                if ($a_pattern)
                {
                        $q .= " AND value like ". $ilDB->quote("%".$a_pattern."%");
                }
                $q .= " ORDER BY module, identifier";
                $set = $ilDB->query($q);

                $trans = array();
                while ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
                {
                        $trans[$rec["module"].$lng->separator.$rec["identifier"]] = $rec["value"];
                }
                return $trans;
        }

Here is the caller graph for this function:

ilObjLanguageExt::_saveTranslations ( a_lang_key,
a_translations = array() 
)

Save a set of translation in the database.

static

Parameters:
string language key
array "module#:#topic" => translation

Definition at line 471 of file class.ilObjLanguageExt.php.

References ilObjLanguage::$key, and ilObject::$lng.

Referenced by importLanguageFile().

        {
                global $ilDB, $lng;
                
                if (!is_array($a_translations))
                {
                        return;
                }
                $save_array = array();
                
                // save the single translations in lng_data
                foreach ($a_translations as $key => $value)
                {
                        $keys = explode($lng->separator, $key);
                        if (count($keys) == 2)
                        {
                                $module = $keys[0];
                                $topic = $keys[1];
                                $save_array[$module][$topic] = $value;
                        
                                $q = "REPLACE INTO lng_data(lang_key, module, identifier, value)"
                                . " VALUES("
                                . $ilDB->quote($a_lang_key). ","
                                . $ilDB->quote($module). ","
                                . $ilDB->quote($topic). ","
                                . $ilDB->quote($value).")";
                                $ilDB->query($q);
                        }
                }

                // save the serialized module entries in lng_modules
                foreach ($save_array as $module => $entries)
                {
                        $q = "SELECT * FROM lng_modules WHERE ".
                                " lang_key = ".$ilDB->quote($a_lang_key).
                                " AND module = ".$ilDB->quote($module);
                        $set = $ilDB->query($q);
                        $row = $set->fetchRow(DB_FETCHMODE_ASSOC);
                        $arr = unserialize($row["lang_array"]);
                        if (is_array($arr))
                        {
                                $entries = array_merge($arr, $entries);
                        }
                        $q = "REPLACE INTO lng_modules (lang_key, module, lang_array) VALUES ".
                                 "(".$ilDB->quote($a_lang_key).", " .
                                 " ".$ilDB->quote($module).", " .
                                 " ".$ilDB->quote(serialize($entries)).") ";
                        $ilDB->query($q);
                }
        }

Here is the caller graph for this function:

ilObjLanguageExt::getAllTranslations ( a_modules = array(),
a_pattern = '' 
)

Get all translation entries from the database.

Parameters:
array list of modules
string search pattern
Returns:
array module#:topic => value

Definition at line 116 of file class.ilObjLanguageExt.php.

References _getTranslations().

Referenced by importLanguageFile().

        {
                return $this->_getTranslations($this->key, $a_modules, NULL, $a_pattern);
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilObjLanguageExt::getChangedTranslations ( a_modules = array(),
a_pattern = '' 
)

Get only the changed translation entries from the database which differ from the original language file.

The language file has to be read first.

Parameters:
array list of modules
string search pattern
Returns:
array module#:topic => translation

Definition at line 131 of file class.ilObjLanguageExt.php.

References ilObjLanguage::$key, and _getTranslations().

Referenced by importLanguageFile().

        {
                $translations = $this->_getTranslations($this->key, $a_modules, NULL, $a_pattern);
                $changes = array();
                
                foreach ($translations as $key => $value)
                {
                        if ($this->lang_file_content[$key] != $value)
                        {
                                $changes[$key] = $value;
                        }
                }
                
                return $changes;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilObjLanguageExt::getCommentedTranslations ( a_modules = array(),
a_pattern = '' 
)

Get all translation entries from the database for wich the original language file has a comment.

The language file has to be read first.

Parameters:
array list of modules
array search pattern
Returns:
array module#:topic => translation

Definition at line 183 of file class.ilObjLanguageExt.php.

References ilObjLanguage::$key, and _getTranslations().

        {
                $translations = $this->_getTranslations($this->key, $a_modules, NULL, $a_pattern);
                $commented = array();

                foreach ($translations as $key => $value)
                {
                        if ($this->lang_file_comments[$key] != "")
                        {
                                $commented[$key] = $value;
                        }
                }

                return $commented;
        }

Here is the call graph for this function:

ilObjLanguageExt::getCustLangPath (  ) 

Get the customized language files path.

Returns:
string path of customized language files folder

Definition at line 104 of file class.ilObjLanguageExt.php.

        {
                return $this->cust_lang_path;
        }

ilObjLanguageExt::getLangFileComments (  ) 

Get all language file comments The language file has to be read first.

Returns:
array key => comment

Definition at line 217 of file class.ilObjLanguageExt.php.

        {
                return $this->lang_file_comments;
        }

ilObjLanguageExt::getLangFileContent (  ) 

Get the whole language file content The language file has to be read first.

Returns:
array key => value

Definition at line 206 of file class.ilObjLanguageExt.php.

        {
                return $this->lang_file_content;
        }

ilObjLanguageExt::getLangFileParam ( a_param  ) 

Get a parameter value from the original language file header.

Parameters are

Version:
,
Author:
, ... The language file has to be read first.
Parameters:
string parameter name
Returns:
string parameter value

Definition at line 231 of file class.ilObjLanguageExt.php.

        {
                return $this->lang_file_param[$a_param];
        }

ilObjLanguageExt::getLangFileValue ( a_module,
a_topic 
)

Get the value of a single language file entry.

This entry may differ from the current database value due to a local language file or to online translations. The language file has to be read first.

Parameters:
string module name
string topic indentifier
Returns:
string language file value

Definition at line 248 of file class.ilObjLanguageExt.php.

        {
                return $this->lang_file_content[$a_module.$this->separator.$a_topic];
        }

ilObjLanguageExt::getLangPath (  ) 

Get the language files path.

Returns:
string path of language files folder

Definition at line 94 of file class.ilObjLanguageExt.php.

        {
                return $this->lang_path;
        }

ilObjLanguageExt::getLongDescription (  ) 

Get the full language description.

Returns:
string description

Reimplemented from ilObject.

Definition at line 84 of file class.ilObjLanguageExt.php.

        {
                return $this->lng->txt($this->desc);
        }

ilObjLanguageExt::getUnchangedTranslations ( a_modules = array(),
a_pattern = '' 
)

Get only the unchanged translation entries from the database which are equal to the original language file.

The language file has to be read first.

Parameters:
array list of modules
array search pattern
Returns:
array module#:topic => translation

Definition at line 157 of file class.ilObjLanguageExt.php.

References ilObjLanguage::$key, and _getTranslations().

        {
                $translations = $this->_getTranslations($this->key, $a_modules, NULL, $a_pattern);
                $unchanged = array();

                foreach ($translations as $key => $value)
                {
                        if ($this->lang_file_content[$key] == $value)
                        {
                                $unchanged[$key] = $value;
                        }
                }

                return $unchanged;
        }

Here is the call graph for this function:

ilObjLanguageExt::ilObjLanguageExt ( a_id = 0,
a_call_by_reference = false 
)

Constructor.

Definition at line 51 of file class.ilObjLanguageExt.php.

References ilObjLanguage::ilObjLanguage().

        {
                $this->ilObjLanguage($a_id, $a_call_by_reference);
        }

Here is the call graph for this function:

ilObjLanguageExt::importLanguageFile ( a_file,
a_mode_existing = 'keepnew' 
)

Import a language file into the ilias database.

Parameters:
string handling of existing values ('keepall','keeknew','replace','delete')

Definition at line 260 of file class.ilObjLanguageExt.php.

References ilObjLanguage::$key, _saveTranslations(), getAllTranslations(), getChangedTranslations(), and readLanguageFile().

        {
                global $ilDB;
                
                switch($a_mode_existing)
                {
                        // keep all existing entries
                        case 'keepall':
                                $to_keep = $this->getAllTranslations();
                                break;

                        // keep existing online changes
                        case 'keepnew':
                            // read the original language file
                            $this->readLanguageFile();
                                $to_keep = $this->getChangedTranslations();
                                break;

                        // replace all existing definitions
                        case 'replace':
                            $to_keep = array();
                            break;

           // delete all existing entries
                        case 'delete':
                                $query = "DELETE FROM lng_data WHERE lang_key='".$this->key."'";
                                $ilDB->query($query);
                                $query = "DELETE FROM lng_modules WHERE lang_key='".$this->key."'";
                                $ilDB->query($query);
                                $to_keep = array();
                                break;
                                
                        default:
                            return;
                }
                
                // read the new language file and process content
                $this->readLanguageFile($a_file);
                $to_save = array();
                foreach ($this->lang_file_content as $key => $value)
                {
                        if (!isset($to_keep[$key]))
                        {
                                $to_save[$key] = $value;
                        }
                }
                $this->_saveTranslations($this->key, $to_save);
        }

Here is the call graph for this function:

ilObjLanguageExt::readLanguageFile ( a_lang_file = ''  ) 

Read the language file content and parameters into class arrays.

Definition at line 313 of file class.ilObjLanguageExt.php.

References ilObjLanguage::$key.

Referenced by importLanguageFile().

        {
                $this->lang_file_param = array();
                $this->lang_file_content = array();
                $this->lang_file_comments = array();

                if ($a_lang_file == '')
                {
                        $a_lang_file = $this->lang_path . "/ilias_" . $this->key . ".lang";
                }
                $content = file($a_lang_file);
                
                $in_header = true;
                foreach ($content as $dummy => $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->lang_file_param[$param] = $value;
                                        }
                                }
                        }
                        else
                        {
                                // separate the lang file entry
                                $separated = explode($this->separator, trim($line));
                                
                                if (count($separated) == 3)
                                {
                                        $key = $separated[0].$this->separator.$separated[1];
                                        $value = $separated[2];

                                        // cut off comment
                                        $pos = strpos($value, $this->comment_separator);
                                        if ($pos !== false)
                                        {
                                                $this->lang_file_comments[$key]
                                                        = substr($value , $pos + strlen($this->comment_separator));
                                                        
                                                $value = substr($value , 0 , $pos);
                                        }
                                        $this->lang_file_content[$key] = $value;
                                }
                        }
                }
        }

Here is the caller graph for this function:

ilObjLanguageExt::setLocal ( a_local = true  ) 

Set the local status of the language.

Parameters:
boolean local status (true/false)

Definition at line 62 of file class.ilObjLanguageExt.php.

References ilObjLanguage::isInstalled(), ilObject::setDescription(), and ilObject::update().

        {
                if ($this->isInstalled())
                {
                        if ($a_local == true)
                        {
                                $this->setDescription("installed_local");
                        }
                        else
                        {
                $this->setDescription("installed");
                        }
                        $this->update();
                }
        }

Here is the call graph for this function:


Field Documentation

ilObjLanguageExt::$lang_file_comments = array()

Definition at line 45 of file class.ilObjLanguageExt.php.

ilObjLanguageExt::$lang_file_content = array()

Definition at line 44 of file class.ilObjLanguageExt.php.

ilObjLanguageExt::$lang_file_param = array()

Definition at line 43 of file class.ilObjLanguageExt.php.


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