예제 #1
0
 public static function getTranlationFactory($TableSource, $ExceptDefLang = true, $Admin = false)
 {
     if ($ExceptDefLang) {
         $LanguageList[STT_DefaultLang] = LngConf_DataBase . "." . $TableSource . '_' . STT_DefaultLang;
     }
     // All language list Should be here without default lang for table defination.
     $LanguageList['az'] = LngConf_DataBase . "." . $TableSource . '_az';
     $params = array('langs_avail_table' => LngConf_LangListTable, 'lang_id_col' => 'Id', 'lang_name_col' => 'Name', 'lang_meta_col' => 'Meta', 'lang_errmsg_col' => 'ErrorText', 'lang_encoding_col' => 'Encoding', 'strings_tables' => $LanguageList, 'string_id_col' => 'StringId', 'string_page_id_col' => 'PageId', 'string_text_col' => 'String');
     $dbinfo = array('hostspec' => DB_HOST, 'database' => LngConf_DataBase, 'phptype' => 'mysql', 'username' => DB_USERNAME, 'password' => DB_PASSWORD);
     if ($Admin) {
         $tr =& Translation2_Admin::factory("MDB2", $dbinfo, $params);
     } else {
         $tr =& Translation2::factory("MDB2", $dbinfo, $params);
     }
     return $tr;
 }
예제 #2
0
파일: Flexy.php 프로젝트: nishimura/Fly
 /**
  * Initilalize the translation methods.
  *
  * Loads Translation2 if required.
  *
  *
  * @return   none
  * @access   public
  */
 function initializeTranslator()
 {
     if (is_array($this->options['Translation2'])) {
         require_once 'Translation2.php';
         $this->options['Translation2'] =& Translation2::factory($this->options['Translation2']['driver'], isset($this->options['Translation2']['options']) ? $this->options['Translation2']['options'] : array(), isset($this->options['Translation2']['params']) ? $this->options['Translation2']['params'] : array());
     }
     if ($this->options['Translation2'] instanceof Translation2) {
         $this->options['Translation2']->setLang($this->options['locale']);
         // fixme - needs to be more specific to which template to use..
         foreach ($this->options['templateDir'] as $tt) {
             $n = basename($this->currentTemplate);
             if (substr($this->currentTemplate, 0, strlen($tt)) == $tt) {
                 $n = substr($this->currentTemplate, strlen($tt) + 1);
             }
             //echo $n;
         }
         $this->options['Translation2']->setPageID($n);
     } elseif (defined('LC_ALL')) {
         // not sure what we should really use here... - used to be LC_MESSAGES.. but that did not make sense...
         setlocale(LC_ALL, $this->options['locale']);
     }
 }
예제 #3
0
 public static function getTranslationHandler()
 {
     if (self::$translation_handler === NULL) {
         if (self::useGetTextExtension() == TRUE) {
             //Debug::Text('Using getText()...', __FILE__, __LINE__, __METHOD__,10);
             return new NativeGettextTranslationHandler();
         } else {
             //Debug::Text('Using Translation2...', __FILE__, __LINE__, __METHOD__,10);
             require_once 'Translation2.php';
             $locale_dir = Environment::getBasePath() . DIRECTORY_SEPARATOR . 'interface' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR;
             // The Translation2 Gettext example has this comment:
             //
             //    "Better set prefetch to FALSE for the gettext container, so we don't need
             //     to read in the whole MO file with File_Gettext on every request."
             //
             // I haven't investigated this fully yet.  So for now I am doing as they advise.
             // Probably worth checking out for performance purposes. Also, it is unclear
             // how this affects PO mode, as opposed to MO.
             $params = array('prefetch' => FALSE, 'langs_avail_file' => $locale_dir . 'langs.ini', 'domains_path_file' => $locale_dir . 'domains.ini', 'default_domain' => 'messages', 'file_type' => 'mo', 'cacheDir' => '/tmp/timetrex/', 'lifeTime' => 86400 * 7);
             self::$translation_handler = Translation2::factory('gettext', $params);
             //self::$translation_handler->getDecorator('CacheLiteFunction');
             // Okay, this is super-gross, as we are modifying private data of the
             // Translation2::storage object.  Why do we do it?  Because the
             // brain-dead Translation2 api for gettext only allows specifying
             // fixed paths via domains.ini file.  Our path depends on our environment
             // and we need to tell it that.  So, it appears we either do this nasty
             // hack, or we have to start modifying the Translation2 code directly.
             self::$translation_handler->storage->_domains = array('messages' => $locale_dir);
         }
     }
     return self::$translation_handler;
 }
예제 #4
0
파일: Translator.php 프로젝트: q32p/emst
 /**
  * process the input 
  *
  * 
  * @param   array   $_GET; (translate = en)
  * @param   array   $_POST; (translate = en, en[{md5}] = translation)
  * @return   none
  * @access   public
  */
 function process($get, $post)
 {
     //DB_DataObject::debugLevel(1);
     $displayLang = isset($get['translate']) ? $get['translate'] : (isset($post['translate']) ? $post['translate'] : false);
     if ($displayLang === false) {
         return;
     }
     require_once 'Translation2/Admin.php';
     $driver = $this->options['Translation2']['driver'];
     $options = $this->options['Translation2']['options'];
     $usingGT = $driver == 'gettext';
     $usingDO = $driver == 'dataobjectsimple';
     $trd =& Translation2_Admin::factory($driver, $options);
     //$trd->setDecoratedLang('en');
     foreach ($this->options['targetLangs'] as $l) {
         $trd->addLang(array('lang_id' => $l));
     }
     // back to parent if no language selected..
     if (!in_array($displayLang, $this->options['targetLangs'])) {
         require_once 'PEAR.php';
         $p = new PEAR();
         return $p->raiseError('Unknown Language :' . $displayLang);
     }
     $this->translate = $displayLang;
     if (isset($post['_apply'])) {
         $this->clearTemplateCache($displayLang);
     }
     $t = explode(' ', microtime());
     $start = $t[0] + $t[1];
     require_once 'Translation2.php';
     $tr =& Translation2::factory($driver, $options);
     $tr->setLang($displayLang);
     if (!$usingDO) {
         $suggestions =& Translation2::factory($driver, $options);
         $suggestions->setLang($displayLang);
     }
     $this->compileAll();
     //$tr->setPageID('test.html');
     // delete them after we have compiled them!!
     if (isset($post['_apply'])) {
         $this->clearTemplateCache($displayLang);
     }
     //DB_DataObject::debugLevel(1);
     if ($usingDO) {
         $this->loadTranslations();
         $this->loadTranslations($displayLang);
     }
     $all = array();
     if ($usingGT) {
         $trd->storage->begin();
     }
     $displayLangClean = str_replace('.', '_', $displayLang);
     foreach ($this->words as $page => $words) {
         $status[$page] = array();
         $tr->setPageID($page);
         // pages....
         if (isset($post['_clear']) && !PEAR::isError($p = $trd->getPage($page, $displayLang))) {
             $diff = array_diff(array_keys($p), $words);
             if (count($diff)) {
                 foreach ($diff as $string) {
                     $trd->remove($string, $page);
                 }
             }
         }
         foreach ($words as $word) {
             if (!strlen(trim($word))) {
                 continue;
             }
             $md5 = md5($page . ':' . $word);
             $value = $usingDO ? $this->getTranslation($page, $word, $displayLang) : $tr->get($word);
             // we posted something..
             if (isset($post[$displayLangClean][$md5])) {
                 // eak we shouldnt really deal with magic_quotes!!!
                 $nval = str_replace("\r\n", "\n", get_magic_quotes_gpc() ? stripslashes($post[$displayLangClean][$md5]) : $post[$displayLangClean][$md5]);
                 if ($value != $nval) {
                     $trd->add($word, $page, array($displayLang => $nval));
                     $value = $nval;
                 }
             }
             if ($value == '') {
                 // try the old gettext...
                 if (isset($old[addslashes($word)])) {
                     $trd->add($word, $page, array($displayLang => $old[addslashes($word)]));
                     $value = $old[addslashes($word)];
                 }
             }
             $add = new StdClass();
             $add->from = $word;
             $add->to = $value;
             if (!$add->to || $add->from == $add->to) {
                 $add->untranslated = true;
                 if ($usingDO) {
                     $add->suggest = implode(', ', $this->getSuggestions($word, $displayLang));
                 } else {
                     $suggest = $suggestions->get($word);
                     if ($suggest && $suggest != $word) {
                         $add->suggest = $suggest;
                     }
                 }
             }
             $add->md5 = $md5;
             // show big or small text entry..
             $add->short = (bool) (strlen($add->from) < 30 && strstr($add->from, "\n") === false);
             $status[$page][] = $add;
         }
     }
     if ($usingGT) {
         $trd->storage->commit();
     }
     $t = explode(' ', microtime());
     $total = $t[0] + $t[1] - $start;
     //printf("Built All in %0.2fs<BR>",$total);
     $this->status = $status;
 }
예제 #5
0
 function __construct($lang)
 {
     $params = array('filename' => dirname(__FILE__) . '/strings.xml');
     require_once 'Translation2.php';
     $this->translation2 = Translation2::factory('XML', $params);
     if (PEAR::isError($this->translation2)) {
         throw new Exception('Could not start Translation2: ' . $this->translation2->getMessage());
     }
     $res = $this->translation2->setLang($lang);
     if (PEAR::isError($res)) {
         throw new Exception('Could not setLang()');
     }
 }
예제 #6
0
 /**
  * Initilalize the translation methods.
  *
  * Loads Translation2 if required.
  *
  *
  * @return   none
  * @access   public
  */
 function initializeTranslator()
 {
     if (is_array($this->options['Translation2'])) {
         require_once 'Translation2.php';
         $this->options['Translation2'] =& Translation2::factory($this->options['Translation2']['driver'], isset($this->options['Translation2']['options']) ? $this->options['Translation2']['options'] : array(), isset($this->options['Translation2']['params']) ? $this->options['Translation2']['params'] : array());
     }
     if (is_a($this->options['Translation2'], 'Translation2')) {
         $this->options['Translation2']->setLang($this->options['locale']);
         // fixme - needs to be more specific to which template to use..
         foreach ($this->options['templateDir'] as $tt) {
             $n = basename($this->currentTemplate);
             if (substr($this->currentTemplate, 0, strlen($tt)) == $tt) {
                 $n = substr($this->currentTemplate, strlen($tt) + 1);
             }
             //echo $n;
         }
         $this->options['Translation2']->setPageID($n);
     } else {
         setlocale(LC_ALL, $this->options['locale']);
     }
 }
 /**
  * Setup for the languageConf class.
  * tell Translation2 about our db-tables structure,
  * setup primary language
  * setup the group of module strings we want to fetch from
  * add a Lang decorator to provide a fallback language
  * add another Lang decorator to provide another fallback language,
  * in case some strings are not translated in all languages that exist in KINKY
  *
  * @param void
  * @return void
  * @access public
  */
 public function setup()
 {
     try {
         $otherLangs = $this->dblangAvail->getLanguageList();
         $entries = array();
         $entries['en'] = TABLE_PREFIX . 'en';
         foreach ($otherLangs as $lang) {
             $id = $lang['id'];
             $entries[$id] = TABLE_PREFIX . $id;
         }
         //Define table properties so that MDB2 knows about them
         $params = array('langs_avail_table' => TABLE_PREFIX . 'langs_avail', 'lang_id_col' => 'id', 'lang_name_col' => 'name', 'lang_meta_col' => 'meta', 'lang_errmsg_col' => 'error_text', 'strings_tables' => $entries, 'string_id_col' => 'id', 'string_page_id_col' => 'pageID', 'string_text_col' => '%s');
         $driver = 'MDB2';
         //instantiate class
         $this->_siteConf = $this->getObject('altconfig', 'config');
         $langcache = $this->_siteConf->getlangcache();
         if (strtolower($langcache) === 'true') {
             $langcache = true;
         } else {
             $langcache = false;
         }
         //$dsn = $this->_parseDSN(KEWL_DB_DSN);
         $dsn = engine::parseDSN_(KEWL_DB_DSN);
         $this->lang =& Translation2::factory($driver, $dsn, $params);
         if (PEAR::isError($this->lang)) {
             echo '!';
             throw new customException($this->lang->getMessage());
         }
         $this->langAdmin =& Translation2_Admin::factory($driver, $dsn, $params);
         // caching
         $this->lang =& $this->lang->getDecorator('CacheMemory');
         $this->lang->setOption('prefetch', true);
         //$this->lang =& $this->lang->getDecorator('CacheLiteFunction');
         // TODO: make the caching configuration options for language items configurable
         $cacheLiteOptions = array('memoryCaching' => false, 'cacheDir' => '/tmp/', 'caching' => $langcache, 'lifeTime' => 3600, 'cleaningFrequency' => 0);
         //$this->lang->setOptions($cacheLiteOptions);
         // charsets
         $this->lang =& $this->lang->getDecorator('SpecialChars');
         // control the charset to use
         $this->lang->setOption('charset', 'UTF-8');
         // add a UTF-8 decorator to automatically decode UTF-8 strings
         $this->lang =& $this->lang->getDecorator('UTF8');
         // add a default text decorator to deal with empty strings
         $this->lang =& $this->lang->getDecorator('DefaultText');
         //default value is true
         if (PEAR::isError($this->lang)) {
             throw new customException($this->lang->getMessage());
         }
         if (!is_object($this->lang)) {
             throw new customException('Translation class not loaded');
         }
         // set primary language
         $this->lang->setLang("en");
         // set the group of strings you want to fetch from
         $this->caller = $this->getParam('module');
         if ($this->caller == '') {
             $page = 'system';
         } else {
             $page = $this->caller;
         }
         // This needs to be dynamic, coming from the module that we are using currently
         $this->lang->setPageID($page);
         // add a Lang decorator to provide a fallback language
         $this->lang =& $this->lang->getDecorator('Lang');
         $this->lang->setOption('fallbackLang', 'en');
         /* $this->lang->setOption('cacheDir', '/var/www/cache/');
            $this->lang->setOption('lifeTime', 86400);
            $this->lang->setOption('cleaningFrequency', 0); */
         // replace the empty string with its stringID
         return $this->lang;
         //}
     } catch (Exception $e) {
         // Alterations by jsc on advice from paulscott
         //$this->errorCallback ('Caught exception: '.$e->getMessage());
         echo $e->getMessage();
         exit;
     }
 }
<?php

/*
* ____          _____   _____ ______ _____  
*|  _ \   /\   |  __ \ / ____|  ____|  __ \ 
*| |_) | /  \  | |  | | |  __| |__  | |__) |
*|  _ < / /\ \ | |  | | | |_ |  __| |  _  / 
*| |_) / ____ \| |__| | |__| | |____| | \ \ 
*|____/_/    \_\_____/ \_____|______|_|  \_\
* Open Source Finance Management
* Visit http://www.badger-finance.org 
*
**/
require_once BADGER_ROOT . '/core/UserSettings.class.php';
$us = new UserSettings($badgerDb);
$driver = 'DB';
$tr =& Translation2::factory($driver, $badgerDbConnectionInfo);
function getBadgerTranslation2($page, $id, $lang = NULL)
{
    global $tr, $us;
    if (!$lang) {
        $usedLanguage = $us->getProperty('badgerLanguage');
    } else {
        $usedLanguage = $lang;
    }
    return $tr->get($id, $page, $usedLanguage);
}