ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilPluginLanguage Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilPluginLanguage:

Public Member Functions

 __construct (ilPluginInfo $plugin_info)
 
 getAvailableLangFiles ()
 Get array of all language files in the plugin. More...
 
 hasAvailableLangFiles ()
 
 getPrefix ()
 
 updateLanguages (?array $a_lang_keys=null)
 
 uninstall ()
 
 loadLanguageModule ()
 Load language module for plugin. More...
 
 txt (string $a_var)
 Get Language Variable (prefix will be prepended automatically) More...
 

Protected Member Functions

 getLanguageDirectory ()
 

Protected Attributes

ilPluginInfo $plugin_info
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Author
Richard Klees richa.nosp@m.rd.k.nosp@m.lees@.nosp@m.conc.nosp@m.epts-.nosp@m.and-.nosp@m.train.nosp@m.ing..nosp@m.de

Definition at line 25 of file class.ilPluginLanguage.php.

Constructor & Destructor Documentation

◆ __construct()

ilPluginLanguage::__construct ( ilPluginInfo  $plugin_info)

Definition at line 29 of file class.ilPluginLanguage.php.

References $plugin_info.

30  {
31  $this->plugin_info = $plugin_info;
32  }

Member Function Documentation

◆ getAvailableLangFiles()

ilPluginLanguage::getAvailableLangFiles ( )

Get array of all language files in the plugin.

Returns
array of [key => "en" (e.g.), file => ...]

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

References getLanguageDirectory().

Referenced by hasAvailableLangFiles(), and updateLanguages().

44  : array
45  {
46  $directory = $this->getLanguageDirectory();
47  if (!@is_dir($directory)) {
48  return [];
49  }
50 
51  $langs = [];
52 
53  $dir = opendir($directory);
54  while ($file = readdir($dir)) {
55  if ($file === "." || $file === "..") {
56  continue;
57  }
58 
59  // directories
60  if (@is_file($directory . "/" . $file) &&
61  strpos($file, "ilias_") === 0 &&
62  substr($file, strlen($file) - 5) === ".lang") {
63  $langs[] = [
64  "key" => substr($file, 6, 2),
65  "file" => $file
66  ];
67  }
68  }
69 
70  return $langs;
71  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLanguageDirectory()

ilPluginLanguage::getLanguageDirectory ( )
protected

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

Referenced by getAvailableLangFiles(), and updateLanguages().

34  : string
35  {
36  return $this->plugin_info->getPath() . "/lang";
37  }
+ Here is the caller graph for this function:

◆ getPrefix()

ilPluginLanguage::getPrefix ( )

Definition at line 78 of file class.ilPluginLanguage.php.

References XapiProxy\$plugin, and $plugin_info.

Referenced by loadLanguageModule(), txt(), uninstall(), and updateLanguages().

78  : string
79  {
81  $component = $plugin->getComponent();
82  $slot = $plugin->getPluginSlot();
83 
84  return $component->getId() . "_" . $slot->getId() . "_" . $plugin->getId();
85  }
+ Here is the caller graph for this function:

◆ hasAvailableLangFiles()

ilPluginLanguage::hasAvailableLangFiles ( )

Definition at line 73 of file class.ilPluginLanguage.php.

References getAvailableLangFiles().

73  : bool
74  {
75  return count($this->getAvailableLangFiles()) > 0;
76  }
getAvailableLangFiles()
Get array of all language files in the plugin.
+ Here is the call graph for this function:

◆ loadLanguageModule()

ilPluginLanguage::loadLanguageModule ( )

Load language module for plugin.

Definition at line 168 of file class.ilPluginLanguage.php.

References $DIC, $lng, and getPrefix().

Referenced by txt().

168  : void
169  {
170  global $DIC;
171  $lng = $DIC->language();
172 
173  if (is_object($lng)) {
174  $lng->loadLanguageModule($this->getPrefix());
175  }
176  }
$lng
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ txt()

ilPluginLanguage::txt ( string  $a_var)

Get Language Variable (prefix will be prepended automatically)

Definition at line 181 of file class.ilPluginLanguage.php.

References $DIC, $lng, getPrefix(), and loadLanguageModule().

181  : string
182  {
183  global $DIC;
184  $lng = $DIC->language();
185  $this->loadLanguageModule();
186 
187  return $lng->txt($this->getPrefix() . "_" . $a_var, $this->getPrefix());
188  }
$lng
global $DIC
Definition: feed.php:28
loadLanguageModule()
Load language module for plugin.
+ Here is the call graph for this function:

◆ uninstall()

ilPluginLanguage::uninstall ( )

Definition at line 145 of file class.ilPluginLanguage.php.

References $DIC, $ilDB, and getPrefix().

145  : void
146  {
147  global $DIC;
148  $ilDB = $DIC->database();
149 
150  // remove all language entries (see ilObjLanguage)
151  // see updateLanguages
152  $prefix = $this->getPrefix();
153  if ($prefix) {
154  $ilDB->manipulate(
155  "DELETE FROM lng_data" .
156  " WHERE module = " . $ilDB->quote($prefix, "text")
157  );
158  $ilDB->manipulate(
159  "DELETE FROM lng_modules" .
160  " WHERE module = " . $ilDB->quote($prefix, "text")
161  );
162  }
163  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

◆ updateLanguages()

ilPluginLanguage::updateLanguages ( ?array  $a_lang_keys = null)

Definition at line 92 of file class.ilPluginLanguage.php.

References Vendor\Package\$a, $lang, $txt, ilObjLanguage\_getLocalChangesByModule(), getAvailableLangFiles(), ilObjLanguage\getInstalledLanguages(), getLanguageDirectory(), getPrefix(), and ilObjLanguage\replaceLangEntry().

92  : void
93  {
94  ilGlobalCache::flushAll();
95 
96  // get the keys of all installed languages if keys are not provided
97  if (!isset($a_lang_keys)) {
98  $a_lang_keys = [];
99  foreach (ilObjLanguage::getInstalledLanguages() as $langObj) {
100  if ($langObj->isInstalled()) {
101  $a_lang_keys[] = $langObj->getKey();
102  }
103  }
104  }
105 
106  $langs = $this->getAvailableLangFiles();
107 
108  $prefix = $this->getPrefix();
109 
110  foreach ($langs as $lang) {
111  // check if the language should be updated, otherwise skip it
112  if (!in_array($lang['key'], $a_lang_keys, true)) {
113  continue;
114  }
115 
116  $txt = file($this->getLanguageDirectory() . "/" . $lang["file"]);
117  $lang_array = [];
118 
119  // get locally changed variables of the module (these should be kept)
120  $local_changes = ilObjLanguage::_getLocalChangesByModule($lang['key'], $prefix);
121 
122  // get language data
123  if (is_array($txt)) {
124  foreach ($txt as $row) {
125  if ($row[0] !== "#" && strpos($row, "#:#") > 0) {
126  $a = explode("#:#", trim($row));
127  $identifier = $prefix . "_" . trim($a[0]);
128  $value = trim($a[1]);
129 
130  if (isset($local_changes[$identifier])) {
131  $lang_array[$identifier] = $local_changes[$identifier];
132  } else {
133  $lang_array[$identifier] = $value;
134  ilObjLanguage::replaceLangEntry($prefix, $identifier, $lang["key"], $value);
135  }
136  //echo "<br>-$prefix-".$prefix."_".trim($a[0])."-".$lang["key"]."-";
137  }
138  }
139  }
140 
141  ilObjLanguage::replaceLangModule($lang["key"], $prefix, $lang_array);
142  }
143  }
static getInstalledLanguages()
Get the language objects of the installed languages.
getAvailableLangFiles()
Get array of all language files in the plugin.
$txt
Definition: error.php:13
static replaceLangEntry(string $a_module, string $a_identifier, string $a_lang_key, string $a_value, string $a_local_change=null, string $a_remarks=null)
Replace lang entry.
$lang
Definition: xapiexit.php:26
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
static _getLocalChangesByModule(string $a_key, string $a_module)
Get the local changes of a language module $a_key Language key $a_module Module key Return array iden...
+ Here is the call graph for this function:

Field Documentation

◆ $plugin_info

ilPluginInfo ilPluginLanguage::$plugin_info
protected

Definition at line 27 of file class.ilPluginLanguage.php.

Referenced by __construct(), and getPrefix().


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