ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilPluginLanguage Class Reference
+ 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

Constructor & Destructor Documentation

◆ __construct()

ilPluginLanguage::__construct ( ilPluginInfo  $plugin_info)

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

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

References $plugin_info.

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 43 of file class.ilPluginLanguage.php.

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

References getLanguageDirectory().

Referenced by hasAvailableLangFiles(), and updateLanguages().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLanguageDirectory()

ilPluginLanguage::getLanguageDirectory ( )
protected

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

33 : string
34 {
35 return $this->plugin_info->getPath() . "/lang";
36 }

Referenced by getAvailableLangFiles(), and updateLanguages().

+ Here is the caller graph for this function:

◆ getPrefix()

ilPluginLanguage::getPrefix ( )

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

77 : string
78 {
80 $component = $plugin->getComponent();
81 $slot = $plugin->getPluginSlot();
82
83 return $component->getId() . "_" . $slot->getId() . "_" . $plugin->getId();
84 }

References XapiProxy\$plugin, and $plugin_info.

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

+ Here is the caller graph for this function:

◆ hasAvailableLangFiles()

ilPluginLanguage::hasAvailableLangFiles ( )

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

72 : bool
73 {
74 return count($this->getAvailableLangFiles()) > 0;
75 }
getAvailableLangFiles()
Get array of all language files in the plugin.

References getAvailableLangFiles().

+ Here is the call graph for this function:

◆ loadLanguageModule()

ilPluginLanguage::loadLanguageModule ( )

Load language module for plugin.

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

165 : void
166 {
167 global $DIC;
168 $lng = $DIC->language();
169
170 if (is_object($lng)) {
171 $lng->loadLanguageModule($this->getPrefix());
172 }
173 }
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26

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

Referenced by txt().

+ 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 178 of file class.ilPluginLanguage.php.

178 : string
179 {
180 global $DIC;
181 $lng = $DIC->language();
182 $this->loadLanguageModule();
183
184 return $lng->txt($this->getPrefix() . "_" . $a_var, $this->getPrefix());
185 }
loadLanguageModule()
Load language module for plugin.

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

+ Here is the call graph for this function:

◆ uninstall()

ilPluginLanguage::uninstall ( )

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

142 : void
143 {
144 global $DIC;
145 $ilDB = $DIC->database();
146
147 // remove all language entries (see ilObjLanguage)
148 // see updateLanguages
149 $prefix = $this->getPrefix();
150 if ($prefix) {
151 $ilDB->manipulate(
152 "DELETE FROM lng_data" .
153 " WHERE module = " . $ilDB->quote($prefix, "text")
154 );
155 $ilDB->manipulate(
156 "DELETE FROM lng_modules" .
157 " WHERE module = " . $ilDB->quote($prefix, "text")
158 );
159 }
160 }

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

+ Here is the call graph for this function:

◆ updateLanguages()

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

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

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

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

+ Here is the call graph for this function:

Field Documentation

◆ $plugin_info

ilPluginInfo ilPluginLanguage::$plugin_info
protected

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

Referenced by __construct(), and getPrefix().


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