* @copyright 2004 by http://wombat.exit0.net * @package wombatSite * @subpackage install */ /** * make tool: language MO files * * create MOs out of POs and installes them * * @version 1.0.0 * @package wombatSite * @subpackage install */ class wbMaker_SystemLang extends wbMaker { /** * information * * @access private * @var array $_info */ var $_info = array( 'maker' => 'SystemLang', 'state' => 'new', 'brief' => 'Install or update language files for the Wombat system', 'msg' => '' ); /** * where the language files are located * * relative to baseDir * * @access private * @var string $_varDir */ var $_moBaseDir = 'var/lang'; /** * where the language files are located * * relative to baseDir * * @access private * @var string $_varDir */ var $_poBaseDir = 'lang'; /** * domains * * @access private * @var string $_domains */ var $_domains = array( 'wombat' ); /** * location of cache files * * @access private * @var string $_baseDir */ var $_systemDir; /** * bring birth! * * @access public * @return boolean $result true on success */ function __construct() { $this->_systemDir = wbFactory::getParam( 'systemDir' ); } /** * php4 constructor wrapper * * @access public * @see __construct() */ function wbMaker_SystemLang() { $this->__construct(); } /** * run... * * @access public * @return boolean true on success, false if any target has failed (or patError object on error!) */ function make() { $moDir = $this->_systemDir . '/' . $this->_moBaseDir; $poDir = $this->_systemDir . '/' . $this->_poBaseDir; if( !is_dir( $poDir ) ) { $this->_info['state'] = 'failed'; $this->_info['msg'] = 'Source directory containing ".po"-files does not exits, path: "'. $poDir .'"!'; return false; } // create folder for machine dependen object files if( !is_dir( $moDir ) ) { $res = @mkdir( $moDir, 0755 ); if( !$res ) { $this->_info['state'] = 'failed'; $this->_info['msg'] = 'Could not create directory for ".mo"-files at "'. $moDir .'"!'; return false; } } foreach( $this->_domains as $dom ) { $langs = array(); $dh = dir( $poDir . '/' . $dom ); if( !$dh ) { $this->_info['state'] = 'failed'; $this->_info['msg'] = 'Could not open source directory: "'. $poDir . '/' . $dom .'"!'; return false; } while( false !== ( $po = $dh->read() ) ) { if( $po[0] == '.' ) { continue; } $lang = explode( '.', $po ); if( count( $lang ) != 2 || $lang[1] != 'po' ) { continue; } $lang = $lang[0]; // create language directories if( !is_dir( $moDir . '/' . $lang ) ) { $res = @mkdir( $moDir . '/' . $lang, 0755 ); if( !$res ) { $this->_info['state'] = 'failed'; $this->_info['msg'] = 'Could not create directory for ".mo"-files at "'. $moDir . '/' . $lang .'"!'; return false; } } // create LC_MESSAGES folder if( !is_dir( $moDir . '/' . $lang . '/LC_MESSAGES') ) { $res = @mkdir( $moDir . '/' . $lang . '/LC_MESSAGES', 0755 ); if( !$res ) { $this->_info['state'] = 'failed'; $this->_info['msg'] = 'Could not create directory for ".mo"-files at "'. $moDir . '/' . $lang . '/LC_MESSAGES"!'; return false; } } // create mo files $exec = 'msgfmt -o ' . $moDir . '/' . $lang . '/LC_MESSAGES/' . $dom . '.mo ' . $poDir . '/' . $dom . '/' . $lang . '.po'; exec( $exec, $output, $retVal ); if( $retVal ) { $this->_info['state'] = 'failed'; $this->_info['msg'] = 'Failed to execute: ' . $exec; return false; } wbDebugger::addMsg( 'Make', 'Create MO for domain: "'. $dom.'" language: "'. $lang .'"', 'SystemLang' ); array_push( $langs, $lang ); } } $this->_info['state'] = 'OK'; $this->_info['msg'] = 'Installed '. count( $langs ) . ' language package(s) for ' . count( $this->_domains ) . ' domain(s)'; return true; } } ?>