* @package Wombat * @subpackage base */ /** * initialize patI18n * * @version 0.3.1 * @package Wombat * @subpackage base */ class WBClass_Creator_patI18n extends WBClass_Creator { /** * call counter * @var int */ private static $count = 0; /** * instanciate new objects * * @param array $params options to create object * @return $obj */ public function instantiate( $parameter = array() ) { $obj = null; if( self::$count ) { ++self::$count; return $obj; } ++self::$count; // add include folders $dir = WBParam::get('wb/dir/system') . '/include/patEx/I18n'; patI18n::addIncludeDir($dir); $dir = WBParam::get('wb/dir/base') . '/include/patEx/I18n'; if (is_dir($dir)) { patI18n::addIncludeDir($dir); } // locale config $config = WBClass::create('WBConfig'); $config->load('locale'); // setup translators $fuzzy = $config->get('locale/fuzzy', 'hide'); $translators = $config->get('translators', array()); // basic module patI18n::addModule('CheckConfig', $config->get('locale', array())); patI18n::addModule('Internal'); // default setup using gettext if ((empty($translators) || empty($translators['modules']))&& function_exists('gettext')) { $params = array( 'module' => 'Gettext', 'defaultdomain' => 'site', 'domains' => array('wombat', 'patForms'), 'fuzzy' => $fuzzy ); $this->addModuleGettext($params); return $obj; } if (!is_array($translators['modules'])) { return $obj; } foreach ($translators['modules'] as $params) { $params['fuzzy'] = $fuzzy; switch ($params['module']) { case 'Gettext': $this->addModuleGettext($params); break; case 'Null': $this->addModuleNull($params); break; case 'MySQL': $this->addModuleMySQL($params); break; case 'Wombat': $this->addModuleWombat($params); break; default: WBClass::load('WBException_Config'); throw new WBException_Config('Unsupportet translation module ' . $params['module'], 1, __CLASS__); break; } } return $obj; } /** * setup translation module Gettext * * Add patI18n_Module_Gettext * * @param array $params */ private function addModuleGettext($params) { $lcMessageDir = WBParam::get('wb/dir/base'). '/var/lang'; $modConf = array( 'domain' => $params['defaultdomain'], 'dir' => $lcMessageDir, 'charset' => 'utf-8', 'domains' => array() ); if (isset($params['domains']) && !empty($params['domains'])) { foreach ($params['domains'] as $domain) $modConf['domains'][] = array( 'domain' => $domain, 'dir' => $lcMessageDir ); } patI18n::addModule('Gettext', $modConf); } /** * setup translation module MySQL * * Add patI18n_Module_MySQL * * @param array $params */ private function addModuleMySQL($params) { $config = WBClass::create('WBConfig'); $config->load('config'); $modConf = array( 'domain' => $params['defaultdomain'], 'domains' => $params['domains'], 'database' => $config->get('db/database'), 'host' => $config->get('db/host'), 'user' => $config->get('db/user'), 'password' => $config->get('db/password'), 'tablemsg' => 'wbi18nmsg', 'tabletrans'=> 'wbi18ntrans' ); patI18n::addModule('MySQL', $modConf); } /** * setup translation module Wombat * * Add patI18n_Module_Wombat * * @param array $params */ private function addModuleWombat($params) { $modConf = array( 'domain' => $params['defaultdomain'], 'domains' => $params['domains'], ); $options = array( 'clang', 'fuzzy' ); foreach ($options as $o) { if (isset($params[$o])) { $modConf[$o] = $params[$o]; } } patI18n::addModule('Wombat', $modConf); } /** * setup translation module Wombat * * Add patI18n_Module_Wombat * * @param array $params */ private function addModuleNull($params) { $modConf = array( ); patI18n::addModule('Null', $modConf); } } ?>