1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
<?php /** * SPAW Editor v.2 Language classes * * Language related classes * * @package spaw2 * @subpackage Language * @author Alan Mendelevich <alan@solmetra.lt> * @copyright UAB Solmetra */
require_once(str_replace('\\\\','/',dirname(__FILE__)).'/config.class.php');
/** * Language class * * Stores and retrieves language specific strings and other information * @package spaw2 * @subpackage Language */ class SpawLang { /** * Holds language abbreviation (like "en", "lt", etc.) * @access private * @var string */ var $lang; /** * Sets current language (abbreviation like "en", "lt", etc.) * @param string $value Language abbreviation */ function setLang($value) { $this->lang = $value; } /** * Gets current language (abbreviation like "en", "lt", etc.) * @returns string Language abbreviation */ function getLang() { return $this->lang; }
/** * Holds name of current module/plugin (used to determine location of language file) * @access private * @var string */ var $module; /** * Sets name of current module/plugin (used to determine location of language file) * @param string $value Module name */ function setModule($value) { $this->module = $value; } /** * Returns the name of current module/plugin (used to determine location of language file) * @returns string Module name */ function getModule() { return $this->module; } /** * Holds name of current language block (section in language file) * @access private * @var string */ var $block; /** * Sets name of current language block (section in language file) * @param string $value Block name */ function setBlock($value) { $this->block = $value; } /** * Returns the name of current language block (section in language file) * @returns string Block name */ function getBlock() { return $this->block; } /** * Holds the charset for the current language file * @access private * @var string */ var $charset; /** * Returns the charset for the current language file * @returns string Charset name */ function getCharset() { return $this->charset; }
/** * Holds desired output charset * @access private * @var string */ var $output_charset; /** * Sets output charset (desired charset for output strings) (USE_ICONV config item should be set to true) * @param string $value Desired output charset */ function setOutputCharset($value) { $this->output_charset = $value; } /** * Returns output charset (desired charset for output strings) (USE_ICONV config item should be set to true) * @returns string */ function getOutputCharset() { return $this->output_charset; }
/** * Holds text direction (ltr or rtl) for current language file * @access private * @var string */ var $dir = 'ltr'; /** * Returns text direction (ltr or rtl) for current language file * @returns string Text direction string */ function getDir() { return $this->dir; } /** * Holds language data * @access private * @var array */ var $lang_data;
/** * Holds English language data * @access private * @var array */ var $en_lang_data;
/** * Constructs SPAW_Lang object * @param string $lang Language abbreviation (like "en", "lt", etc.) */ function SpawLang($lang = '') { if ($lang == '') { // default lang $this->lang = SpawConfig::getStaticConfigValue("default_lang"); } else { $this->lang = $lang; } // load core data $this->loadData('core'); }
/** * Loads language data into {@link $lang_data} array * @param string $module Module name */ function loadData($module) { $spaw_root = SpawConfig::getStaticConfigValue("SPAW_ROOT");
if (file_exists($spaw_root.'plugins/'.$module.'/lib/lang/'.$this->lang.'.lang.inc.php')) { // language data for selected language $filename = $spaw_root.'plugins/'.$module.'/lib/lang/'.$this->lang.'.lang.inc.php'; } else { // english language file $filename = $spaw_root.'plugins/'.$module.'/lib/lang/en.lang.inc.php'; }
@include($filename); if ($module == 'core' || empty($this->charset)) { $this->charset = $spaw_lang_charset; if (!empty($spaw_lang_direction)) $this->dir = $spaw_lang_direction; } $this->lang_data[$module] = $spaw_lang_data; if ($this->lang != 'en') { // additionally load English language file for backup purposes $filename = $spaw_root.'plugins/'.$module.'/lib/lang/en.lang.inc.php'; @include($filename); $this->en_lang_data[$module] = $spaw_lang_data; } else { $this->en_lang_data[$module] = $spaw_lang_data; } }
/** * Returns message string * @param string $message Message id * @param string $block Block id * @param string $module Module name * @returns string */ function getMessage($message, $block='', $module='') { $_module = ($module == '')?$this->module:$module; $_block = ($block == '')?$this->block:$block; if (empty($this->lang_data[$_module])) { // load module data $this->loadData($_module); } $msg = ''; if (!empty($this->lang_data[$_module][$_block][$message])) { $msg = $this->lang_data[$_module][$_block][$message]; } else if (!empty($this->en_lang_data[$_module][$_block][$message])) { $msg = $this->en_lang_data[$_module][$_block][$message]; } if ($msg != '') { if (SpawConfig::getStaticConfigValue("USE_ICONV") && isset($this->output_charset) && $this->charset != $this->output_charset) { // convert charsets (ignore illegal characters) $msg = iconv($this->charset, $this->output_charset.'//IGNORE', $msg); } // return message return $msg; } else { // return empty string return ''; } } /** * Shortcut for {@link getMessage()} */ function m($message, $block='', $module='') { return $this->getMessage($message, $block, $module); } } // SPAW_Lang
?>
|