コード例 #1
0
ファイル: Admin.php プロジェクト: altesien/FinalProject
 /**
  * Return a Translation2_Admin instance already initialized
  *
  * @param string $driver  Type of the storage driver
  * @param mixed  $options Additional options for the storage driver
  *                        (example: if you are using DB as the storage
  *                        driver, you have to pass the DSN string here)
  * @param array  $params  Array of parameters for the adapter class
  *                        (i.e. you can set here the mappings between your
  *                        table/field names and the ones used by this class)
  *
  * @return object Translation2 instance or PEAR_Error on failure
  * @access public
  * @static
  */
 function &factory($driver, $options = '', $params = array())
 {
     $tr = new Translation2_Admin();
     $tr->storage = Translation2_Admin::_storageFactory($driver, $options);
     if (PEAR::isError($tr->storage)) {
         return $tr->storage;
     }
     $tr->_setDefaultOptions();
     $tr->_parseOptions($params);
     $tr->storage->_parseOptions($params);
     return $tr;
 }
コード例 #2
0
function modifyTranslation($page, $id, $de, $en)
{
    global $driver;
    global $badgerDbConnectionInfo;
    $tra =& Translation2_Admin::factory($driver, $badgerDbConnectionInfo);
    $tra->update($id, $page, array('de' => $de, 'en' => $en));
}
コード例 #3
0
ファイル: LangConfig.php プロジェクト: makinuk/Qcore
 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;
 }
コード例 #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
*|  _ \   /\   |  __ \ / ____|  ____|  __ \ 
*| |_) | /  \  | |  | | |  __| |__  | |__) |
*|  _ < / /\ \ | |  | | | |_ |  __| |  _  / 
*| |_) / ____ \| |__| | |__| | |____| | \ \ 
*|____/_/    \_\_____/ \_____|______|_|  \_\
* Open Source Finance Management
* Visit http://www.badger-finance.org 
*
**/
define("BADGER_ROOT", "../..");
require_once BADGER_ROOT . "/includes/fileHeaderFrontEnd.inc.php";
// set the parameters to connect to your db
$dbinfo = array('hostspec' => DB_HOST, 'database' => DB_DATABASE_NAME, 'phptype' => DB_TYPE, 'username' => DB_USERNAME, 'password' => DB_PASSWORD);
$driver = 'DB';
require_once BADGER_ROOT . '/core/Translation2/Admin.php';
$tra =& Translation2_Admin::factory($driver, $dbinfo);
if (PEAR::isError($tra)) {
    die($tra->getMessage());
}
// If required variables have been $_POSTed, add a new Translation
// using the $_POSTed variables.
if (isset($_POST['formsent']) && $_POST['formsent'] == "1") {
    if (isset($_POST['id']) && $_POST['id'] == "") {
        die("Missing ID. Translation was not added.<br/><br/>");
    }
    if (isset($_POST['page']) && $_POST['page'] == "") {
        die("Missing page. Translation was not added.<br/><br/>");
    }
    $langs = $tra->getLangs();
    $stringArray = array();
    foreach ($langs as $key => $value) {
コード例 #6
0
 /**
  * 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';
     $trd = new Translation2_Admin('dataobjectsimple', 'translations');
     //$trd->setDecoratedLang('en');
     foreach ($this->options['targetLangs'] as $l) {
         $trd->createNewLang(array('lang_id' => $l));
     }
     // back to parent if no language selected..
     if (!in_array($displayLang, $this->options['targetLangs'])) {
         require_once 'PEAR.php';
         return PEAR::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 = new Translation2('dataobjectsimple', 'translations');
     $tr->setLang($displayLang);
     //$suggestions = new Translation2('dataobjectsimple','translations');
     //$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);
     $this->loadTranslations();
     $this->loadTranslations($displayLang);
     $all = array();
     foreach ($this->words as $page => $words) {
         $status[$page] = array();
         $tr->setPageID($page);
         // pages....
         foreach ($words as $word) {
             if (!trim(strlen($word))) {
                 continue;
             }
             $md5 = md5($page . ':' . $word);
             //$value = $tr->get($word);
             $value = $this->getTranslation($page, $word, $displayLang);
             // we posted something..
             if (isset($post[$displayLang][$md5])) {
                 $nval = get_magic_quotes_gpc() ? stripslashes($post[$displayLang][$md5]) : $post[$displayLang][$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;
                 $add->suggest = implode(', ', $this->getSuggestions($word, $displayLang));
                 //$suggest = $suggestions->get($word);
                 //if ($suggest && ($suggest  != $word)) {
                 //    $add->suggest = $suggestions->get($word);
                 //}
             }
             $add->md5 = $md5;
             $add->short = (bool) (strlen($add->from) < 30);
             $status[$page][] = $add;
         }
     }
     $t = explode(' ', microtime());
     $total = $t[0] + $t[1] - $start;
     //printf("Built All in %0.2fs<BR>",$total);
     $this->status = $status;
 }
コード例 #7
0
 /**
  * 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;
     }
 }
コード例 #8
0
 /**
  * @param $file_name
  * @param bool $save_on_shutdown
  * @param bool $getEx
  * @param string $file_name_pages
  * @return object|Translation2_Admin
  */
 function createTrAdmin($file_name, $save_on_shutdown = false, $getEx = false, $file_name_pages = '')
 {
     list($driver, $options) = $this->_getTrMetaData($file_name, $save_on_shutdown, $getEx, $file_name_pages);
     $tr_admin = Translation2_Admin::factory($driver, $options);
     return $tr_admin;
 }