parse_lang_file(JPATH_INSTALLATION.DS.'lang'.DS.'en.ini'); // Try to get user's preffered language (set in browser's settings and transmitted through the request) $prefLang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); $prefFileName = JPATH_INSTALLATION.DS.'lang'.DS.$prefLang.'.ini'; if( file_exists($prefFileName) && ($prefLang != 'en') ) { $langLocal = $this->parse_lang_file($prefFileName); $this->_lang = array_merge($langEnglish, $langLocal); unset( $langLocal ); unset( $langEnglish ); } else { $this->_lang = $langEnglish; } } function parse_lang_file($filename) { $ret = array(); if(!file_exists($filename)) return array(); $lines = file($filename); foreach($lines as $line) { $line = ltrim($line); if( (substr($line,0,1) == '#') || (substr($line,0,2) == '//') ) continue; $entries = explode('=',$line,2); if(isset($entries[1])) $ret[$entries[0]] = rtrim($entries[1],"\n\r"); } return $ret; } /** * Performs the real translation of the static _() function * @param $key string Translation key * @return string Translation text */ function _realTranslate($key) { if(array_key_exists($key, $this->_lang)) { return $this->_lang[$key]; } else { return $key; } } /** * Returns the translation text of a given key * @param $key string Translation key * @return string Translation text * @static */ public static function _($key) { static $instance; if(!is_object($instance)) { $instance =& ABIText::getInstance(); } return $instance->_realTranslate($key); } }