예제 #1
0
 function getFormTemplate()
 {
     $atts =& $this->_table->attributes();
     import('Dataface/TranslationTool.php');
     $tt = new Dataface_TranslationTool();
     $status_selector_html = $tt->getHTMLStatusSelector($this->_record, $this->destinationLanguage, '__translation__[status]');
     $trec =& $tt->getTranslationRecord($this->_record, $this->destinationLanguage);
     $strec =& $tt->getTranslationRecord($this->_record, $this->sourceLanguage);
     return "\n\t\t\t\t<form{attributes}>\n\t\t\t\t\t<fieldset>\n\t\t\t\t\t<legend>" . $atts['label'] . "</legend>\n\t\t\t\t\t<table class=\"translation-form-table\">\n\t\t\t\t\t<thead>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th width=\"150\" class=\"translation-label-cell-header\"><!-- Field name--></th>\n\t\t\t\t\t\t\t<th width=\"325\" class=\"source-translation-cell-header\">" . df_translate('scripts.Dataface.TranslationForm.LABEL_SOURCE_TRANSLATION', 'Source Translation') . "</th>\n\t\t\t\t\t\t\t<th width=\"325\" class=\"destination-translation-cell-header\">" . df_translate('scripts.Dataface.TranslationForm.LABEL_DESTINATION_TRANSLATION', 'Destination Translation') . "</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</thead>\n\t\t\t\t\t<tbody>\n\t\t\t\t\t\t<tr><th>" . df_translate('scripts.Dataface.TranslationForm.LABEL_TRANSLATION_STATUS', 'Translation Status') . ":</th>\n\t\t\t\t\t\t\t<td>" . df_translate('scripts.Dataface.TranslationForm.LABEL_VERSION', 'Version') . ": " . $strec->val('version') . "</td>\n\t\t\t\t\t\t\t<td>{$status_selector_html} Version: " . $trec->val('version') . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t{content}\n\t\t\t\t\t</tbody>\n\t\t\t\t\t</table>\n\t\t\t\t\t</fieldset>\n\t\t\t\t</form>";
 }
예제 #2
0
 function test_getTranslationRecord()
 {
     $app =& Dataface_Application::getInstance();
     $record = df_get_record('Profiles', array('id' => 10));
     $tt = new Dataface_TranslationTool();
     $enrec = $tt->getTranslationRecord($record, 'en');
     $frrec = $tt->getTranslationRecord($record, 'fr');
     $this->assertEquals('id=10', $enrec->val('record_id'));
     $this->assertEquals(1, $enrec->val('id'));
 }
예제 #3
0
 function processForm($values)
 {
     ini_set('max_execution_time', 900);
     import('Dataface/IO.php');
     import('Dataface/TranslationTool.php');
     $tt = new Dataface_TranslationTool();
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     if (strlen($values['-sourceLanguage']) != 2 || strlen($values['-destinationLanguage']) != 2) {
         trigger_error('Invalid input for languages.  Expected a 2 digit language code.', E_USER_ERROR);
     }
     $values['-limit'] = 500;
     //$qt = new Dataface_QueryTool($this->table->tablename, $app->db(), $values);
     //$qt->loadSet();
     //$it =& $qt->iterator();
     $q = $query;
     $q['-limit'] = 9999;
     if (@$q['--limit']) {
         $q['-limit'] = $q['--limit'];
     }
     $it =& df_get_records($this->table->tablename, $q);
     $keycols = array_keys($this->table->keys());
     $cols = $this->table->getTranslation($values['-destinationLanguage']);
     if (!is_array($cols)) {
         trigger_error('Could not find any columns to be translated in table ' . $values['-destinationLanguage'] . Dataface_Error::printStackTrace(), E_USER_ERROR);
     }
     $babelfish = $this->getTranslator();
     //new babelfish();
     if (isset($app->_conf['google_translate_url'])) {
         $babelfish->google_url_webpage = $app->_conf['google_translate_url'];
     }
     $ioSrc = new Dataface_IO($this->table->tablename);
     $ioSrc->lang = $values['-sourceLanguage'];
     $languageCodes = new I18Nv2_Language('en');
     $ioDest = new Dataface_IO($this->table->tablename);
     $ioDest->lang = $values['-destinationLanguage'];
     $count = 0;
     $to_be_translated = array();
     $destObjects = array();
     while ($it->hasNext()) {
         $curr =& $it->next();
         $translationInfo =& $tt->getTranslationRecord($curr, $values['-destinationLanguage']);
         if ($translationInfo and $translationInfo->val('translation_status') == TRANSLATION_STATUS_NEEDS_UPDATE_MACHINE) {
             $t_needsUpdate = true;
         } else {
             $t_needsUpdate = false;
         }
         $translation_text = array();
         $keyvals = $curr->vals($keycols);
         $srcObject = new Dataface_Record($this->table->tablename, array());
         $destObject = new Dataface_Record($this->table->tablename, array());
         $ioSrc->read($keyvals, $srcObject);
         $ioDest->read($keyvals, $destObject);
         $keyvalsQuery = $keyvals;
         foreach ($keyvals as $key => $val) {
             $keyvalsQuery[$key] = '=' . $keyvals[$key];
         }
         $qb = new Dataface_QueryBuilder($this->table->tablename, $keyvalsQuery);
         $sql = "select * from `" . $this->table->tablename . "_" . $values['-destinationLanguage'] . "` " . $qb->_where();
         $res = mysql_query($sql, $app->db());
         if (!$res) {
             trigger_error(mysql_error($app->db()) . 'SQL : ' . $sql . " Stacktrace:" . Dataface_Error::printStackTrace(), E_USER_ERROR);
         }
         $queryResult = mysql_fetch_array($res);
         if (!$queryResult) {
             $queryResult = array();
         }
         foreach ($cols as $col) {
             if (in_array($col, $keycols)) {
                 continue;
             }
             if (!$this->table->isText($col) and !$this->table->isChar($col)) {
                 continue;
             }
             if (!isset($queryResult[$col]) || $t_needsUpdate) {
                 //$updateRequired = true;
             } else {
                 continue;
             }
             $translation_text[$col] = $srcObject->getValue($col);
         }
         if (count($translation_text) > 0) {
             $to_be_translated[] =& $translation_text;
             $destObjects[] =& $destObject;
         }
         unset($curr);
         unset($srcObject);
         unset($destObject);
         unset($qb);
         unset($translatedRecord);
         unset($translation_text);
         unset($translationInfo);
     }
     $translated = $this->translate($to_be_translated, $values['-sourceLanguage'], $values['-destinationLanguage'], $babelfish);
     if (PEAR::isError($translated)) {
         return $translated;
     }
     foreach ($translated as $rowid => $row) {
         if ($translated[$rowid] == $to_be_translated[$rowid]) {
             continue;
         }
         $update = false;
         foreach ($row as $col => $val) {
             if (strlen(trim($val)) === 0) {
                 continue;
             }
             $destObjects[$rowid]->setValue($col, $val);
             $update = true;
         }
         if ($update) {
             $res = $ioDest->write($destObjects[$rowid]);
             if (PEAR::isError($res)) {
                 trigger_error($res->toString() . Dataface_Error::printStackTrace(), E_USER_ERROR);
             }
             $tt->setTranslationStatus($destObjects[$rowid], $ioDest->lang, TRANSLATION_STATUS_MACHINE);
         }
     }
 }