1
1
<?php (defined ('BASEPATH ' )) OR exit ('No direct script access allowed ' );
2
+ error_reporting (-1 );
3
+ ini_set ('display_errors ' , 1 );
2
4
/**
3
5
* Modular Extensions Revamped - HMVC-RV
4
6
*
@@ -34,17 +36,71 @@ class MX_Lang extends CI_Lang
34
36
{
35
37
public function load ($ langfile , $ lang = '' , $ return = FALSE , $ add_suffix = TRUE , $ alt_path = '' , $ _module = '' )
36
38
{
37
- if (is_array ($ langfile ))
39
+ /* if (is_array($langfile))
38
40
{
39
41
foreach($langfile as $_lang) $this->load($_lang);
40
42
return $this->language;
43
+ }*/
44
+
45
+ if (is_array ($ langfile ))
46
+ {
47
+ foreach ($ langfile as $ value )
48
+ {
49
+ $ this ->load ($ value , $ idiom , $ return , $ add_suffix , $ alt_path );
50
+ }
51
+
52
+ return ;
53
+ }
54
+
55
+ // Path Information
56
+ $ elements = Modules::mx_element_pathinfo ($ langfile , 'lang ' );
57
+
58
+ // Tracking Name
59
+ $ tracking = Modules::mx_element_track ($ elements );
60
+
61
+ //$deft_lang = CI::$APP->config->item('language');
62
+ //$idiom = ($lang == '') ? $deft_lang : $lang;
63
+
64
+ if (empty ($ idiom ) OR ! preg_match ('/^[a-z_-]+$/i ' , $ idiom ))
65
+ {
66
+ $ config =& get_config ();
67
+ $ idiom = empty ($ config ['language ' ]) ? 'english ' : $ config ['language ' ];
41
68
}
42
-
43
- $ deft_lang = CI ::$ APP ->config ->item ('language ' );
44
- $ idiom = ($ lang == '' ) ? $ deft_lang : $ lang ;
69
+
70
+
71
+ if ($ return === FALSE &&
72
+ isset ($ this ->is_loaded [$ tracking ]) &&
73
+ $ this ->is_loaded [$ tracking ] === $ idiom )
74
+ {
75
+ return ;
76
+ }
77
+
45
78
46
- if (in_array ($ langfile .'_lang ' .EXT , $ this ->is_loaded , TRUE ))
47
- return $ this ->language ;
79
+ //if (in_array($tracking, $this->is_loaded, TRUE))
80
+ // return $this->language;
81
+
82
+
83
+ // Load Languges
84
+ foreach (array_reverse (Modules::mx_module_paths ()) as $ path ) {
85
+
86
+ // Full Path to File
87
+ $ file = Modules::mx_element_path ($ path ,'language/ ' .$ idiom ,$ elements );
88
+ //$basepath = BASEPATH.'language/'.$idiom.'/'.$langfile;
89
+ //echo $file . "\r\n";
90
+
91
+ if (realpath ($ file )) {
92
+ include (realpath ($ file ));
93
+ $ found = TRUE ;
94
+ // break;
95
+
96
+ //include_once(realpath($file));
97
+ //continue;
98
+ // $this->is_loaded[] = $tracking;
99
+ }
100
+ }
101
+
102
+
103
+ /*
48
104
49
105
$_module OR $_module = CI::$APP->router->fetch_module();
50
106
list($path, $_langfile) = Modules::find($langfile.'_lang', $_module, 'language/'.$idiom.'/');
@@ -60,11 +116,141 @@ public function load($langfile, $lang = '', $return = FALSE, $add_suffix = TRUE,
60
116
{
61
117
if ($return) return $lang;
62
118
$this->language = array_merge($this->language, $lang);
63
- $ this ->is_loaded [] = $ langfile . ' _lang ' . EXT ;
119
+ $this->is_loaded[] = $tracking ;
64
120
unset($lang);
65
121
}
66
122
}
67
123
68
- return $ this ->language ;
124
+ $this->is_loaded[$tracking] = $idiom;
125
+ //$this->language = array_merge($this->language, $lang);
126
+
127
+ log_message('info', 'Language file loaded: language/'.$idiom.'/'.$langfile); */
128
+ if ($ found !== TRUE )
129
+ {
130
+ show_error ('Unable to load the requested language file: language/ ' .$ idiom .'/ ' .$ langfile );
131
+ }
132
+
133
+ if ( ! isset ($ lang ) OR ! is_array ($ lang ))
134
+ {
135
+ log_message ('error ' , 'Language file contains no data: language/ ' .$ idiom .'/ ' .$ langfile );
136
+
137
+ if ($ return === TRUE )
138
+ {
139
+ return array ();
140
+ }
141
+ return ;
142
+ }
143
+
144
+ if ($ return === TRUE )
145
+ {
146
+ return $ lang ;
147
+ }
148
+
149
+ $ this ->is_loaded [$ tracking ] = $ idiom ;
150
+ $ this ->language = array_merge ($ this ->language , $ lang );
151
+
152
+ log_message (
153
+ 'info ' ,
154
+ 'Language file loaded: language/ ' .$ idiom .'/ ' .$ langfile
155
+ );
156
+ //print_r(get_instance()->load->get_package_paths(TRUE));
157
+ return TRUE ;
158
+
159
+ }
160
+
161
+ //
162
+ //
163
+ //
164
+
165
+ public function xload ($ langfile , $ idiom = '' , $ return = FALSE , $ add_suffix = TRUE , $ alt_path = '' )
166
+ {
167
+ if (is_array ($ langfile ))
168
+ {
169
+ foreach ($ langfile as $ value )
170
+ {
171
+ $ this ->load ($ value , $ idiom , $ return , $ add_suffix , $ alt_path );
172
+ }
173
+
174
+ return ;
175
+ }
176
+
177
+ $ langfile = str_replace ('.php ' , '' , $ langfile );
178
+
179
+ if ($ add_suffix === TRUE )
180
+ {
181
+ $ langfile = preg_replace ('/_lang$/ ' , '' , $ langfile ).'_lang ' ;
182
+ }
183
+
184
+ $ langfile .= '.php ' ;
185
+
186
+ if (empty ($ idiom ) OR ! preg_match ('/^[a-z_-]+$/i ' , $ idiom ))
187
+ {
188
+ $ config =& get_config ();
189
+ $ idiom = empty ($ config ['language ' ]) ? 'english ' : $ config ['language ' ];
190
+ }
191
+
192
+ if ($ return === FALSE && isset ($ this ->is_loaded [$ langfile ]) && $ this ->is_loaded [$ langfile ] === $ idiom )
193
+ {
194
+ return ;
195
+ }
196
+
197
+ // Load the base file, so any others found can override it
198
+ $ basepath = BASEPATH .'language/ ' .$ idiom .'/ ' .$ langfile ;
199
+ if (($ found = file_exists ($ basepath )) === TRUE )
200
+ {
201
+ include ($ basepath );
202
+ }
203
+
204
+ // Do we have an alternative path to look in?
205
+ if ($ alt_path !== '' )
206
+ {
207
+ $ alt_path .= 'language/ ' .$ idiom .'/ ' .$ langfile ;
208
+ if (file_exists ($ alt_path ))
209
+ {
210
+ include ($ alt_path );
211
+ $ found = TRUE ;
212
+ }
213
+ }
214
+ else
215
+ {
216
+ foreach (get_instance ()->load ->get_package_paths (TRUE ) as $ package_path )
217
+ {
218
+ $ package_path .= 'language/ ' .$ idiom .'/ ' .$ langfile ;
219
+ if ($ basepath !== $ package_path && file_exists ($ package_path ))
220
+ {
221
+ include ($ package_path );
222
+ $ found = TRUE ;
223
+ break ;
224
+ }
225
+ }
226
+ }
227
+
228
+ if ($ found !== TRUE )
229
+ {
230
+ show_error ('Unable to load the requested language file: language/ ' .$ idiom .'/ ' .$ langfile );
231
+ }
232
+
233
+ if ( ! isset ($ lang ) OR ! is_array ($ lang ))
234
+ {
235
+ log_message ('error ' , 'Language file contains no data: language/ ' .$ idiom .'/ ' .$ langfile );
236
+
237
+ if ($ return === TRUE )
238
+ {
239
+ return array ();
240
+ }
241
+ return ;
242
+ }
243
+
244
+ if ($ return === TRUE )
245
+ {
246
+ return $ lang ;
247
+ }
248
+
249
+ $ this ->is_loaded [$ langfile ] = $ idiom ;
250
+ $ this ->language = array_merge ($ this ->language , $ lang );
251
+
252
+ log_message ('info ' , 'Language file loaded: language/ ' .$ idiom .'/ ' .$ langfile );
253
+ return TRUE ;
69
254
}
255
+
70
256
}
0 commit comments