00001 <?php
00003
00004
00005
00006
00007
00008
00010
00099 function _T($key, $language = '')
00100 {
00101 static $instance = null;
00102 if (!isset($instance['obj'])) {
00103 $instance = array();
00104 $obj =& FLEA::getSingleton('FLEA_Language');
00105 $instance = array('obj' => & $obj);
00106 }
00107 return $instance['obj']->get($key, $language);
00108 }
00109
00119 function load_language($dictname, $language = '', $noException = false)
00120 {
00121 static $instance = null;
00122 if (!isset($instance['obj'])) {
00123 $instance = array();
00124 $obj =& FLEA::getSingleton('FLEA_Language');
00125 $instance = array('obj' => & $obj);
00126 }
00127 return $instance['obj']->load($dictname, $language, $noException);
00128 }
00129
00137 class FLEA_Language
00138 {
00144 var $_dict = array();
00145
00151 var $_loadedFiles = array();
00152
00158 function FLEA_Language()
00159 {
00160 $autoload = FLEA::getAppInf('autoLoadLanguage');
00161 if (!is_array($autoload)) {
00162 $autoload = explode(',', $autoload);
00163 }
00164 foreach ($autoload as $load) {
00165 $load = trim($load);
00166 if ($load != '') {
00167 $this->load($load);
00168 }
00169 }
00170 }
00171
00188 function load($dictname, $language = '', $noException = false)
00189 {
00190 $dictnames = explode(',', $dictname);
00191 foreach ($dictnames as $dictname) {
00192 $dictname = trim($dictname);
00193 if ($dictname == '') { continue; }
00194
00195 $dictname = preg_replace('/[^a-z0-9\-_]+/i', '', strtolower($dictname));
00196 $language = preg_replace('/[^a-z0-9\-_]+/i', '', strtolower($language));
00197 if ($language == '') {
00198 $language = FLEA::getAppInf('defaultLanguage');
00199 $default = true;
00200 } else {
00201 $default = false;
00202 }
00203
00204 $filename = FLEA::getAppInf('languageFilesDir') . DS .
00205 $language . DS . $dictname . '.php';
00206 if (isset($this->_loadedFiles[$filename])) { continue; }
00207
00208 if (is_readable($filename)) {
00209 $dict = require($filename);
00210 $this->_loadedFiles[$filename] = true;
00211 if (isset($this->_dict[$language])) {
00212 $this->_dict[$language] = array_merge($this->_dict[$language], $dict);
00213 } else {
00214 $this->_dict[$language] = $dict;
00215 }
00216 if ($default) {
00217 $this->_dict[0] =& $this->_dict[$language];
00218 }
00219 } else if (!$noException) {
00220 FLEA::loadClass('FLEA_Exception_ExpectedFile');
00221 return __THROW(new FLEA_Exception_ExpectedFile($filename));
00222 }
00223 }
00224 }
00225
00234 function get($key, $language = '')
00235 {
00236 if ($language == '') { $language = 0; }
00237 return isset($this->_dict[$language][$key]) ?
00238 $this->_dict[$language][$key] :
00239 $key;
00240 }
00241 }