function handle(&$params) { $app =& Dataface_Application::getInstance(); if (!isset($_POST['--confirm_invalidate'])) { return PEAR::raiseError("Cannot invalidate translations with a GET request. Please provide the POST parameter '--confirm_invalidate'"); } $record =& $app->getRecord(); if (!$record) { return PEAR::raiseError("Attempt to invalidate translations on null record. No record could be found to match the query parameters."); } import('Dataface/TranslationTool.php'); $tt = new Dataface_TranslationTool(); $res = $tt->markNewCanonicalVersion($record, $app->_conf['default_language']); if (PEAR::isError($res)) { return $res; } $query =& $app->getQuery(); if (isset($query['--redirect'])) { header('Location: ' . $query['--redirect'] . '&--msg=' . urlencode("Translations successfully invalidated.")); exit; } else { header('Location: ' . $record->getURL('-action=edit') . '&--msg=' . urlencode('Translations successfully invalidated.')); exit; } }
function processForm($values) { $records =& $this->getRecords(); $tt = new Dataface_TranslationTool(); foreach ($records as $record) { $tt->setTranslationStatus($record, $values['--language'], $values['--status']); } }
function handle(&$params) { $app =& Dataface_Application::getInstance(); $tt = new Dataface_TranslationTool(); if (!Dataface_Table::tableExists('dataface__translation_submissions', false)) { $tt->createTranslationSubmissionsTable(); header('Location: ' . $app->url('')); exit; } if (!@$_POST['--submit']) { df_display(array('query' => $app->getQuery(), 'success' => @$_REQUEST['--success']), 'Dataface_submit_translation.html'); exit; } else { if (@$_POST['subject']) { // This is a dummy field - possible hacking attempt header('Location: ' . $app->url('-action=list')); exit; } if (@$_POST['--recordid']) { $record = df_get_record_by_id($_POST['--recordid']); $values = array('record_id' => @$_POST['--recordid'], 'language' => @$_POST['--language'], 'url' => @$_POST['--url'], 'original_text' => @$_POST['--original_text'], 'translated_text' => @$_POST['--translated_text'], 'translated_by' => @$_POST['--translated_by']); $trec = new Dataface_Record('dataface__translation_submissions', array()); $trec->setValues($values); $trec->save(); $email = <<<END The following translation was submitted to the web site {$app->url('')}: Translation for record {$record->getTitle()} which can be viewed at {$record->getURL('-action=view')}. This translation was submitted by {$_POST['--translated_by']} after viewing the content at {$_POST['--url']}. The original text that was being translated is as follows: {$_POST['--original_text']} The translation proposed by this person is as follows: {$_POST['--translated_text']} For more details about this translation, please visit {$trec->getURL('-action=view')}. END; if (@$app->_conf['admin_email']) { mail($app->_conf['admin_email'], 'New translation submitted', $email); } if (@$_POST['--redirect'] || @$_POST['--url']) { $url = @$_POST['--redirect'] ? $_POST['--redirect'] : $_POST['--url']; header('Location: ' . $url . '&--msg=' . urlencode('Thank you for your submission.')); exit; } else { header('Location: ' . $app->url('') . '&--success=1&--msg=' . urlencode('Thank you for your submission.')); exit; } } else { trigger_error("No record id was provided", E_USER_ERROR); } } }
function test_migrateDefaultLanguage() { $app =& Dataface_Application::getInstance(); $vals = xf_db_fetch_assoc(xf_db_query("select * from PeopleIntl where PersonID=1", $app->db())); $this->assertEquals("Default Position", $vals['Position']); $vals2 = xf_db_fetch_assoc(xf_db_query("select * from PeopleIntl where PersonID=2", $app->db())); $this->assertEquals("Default Position 2", $vals2['Position']); $tt = new Dataface_TranslationTool(); $tt->migrateDefaultLanguage('en', array('PeopleIntl')); $vals = xf_db_fetch_assoc(xf_db_query("select * from PeopleIntl where PersonID=1", $app->db())); $this->assertEquals("My English Position", $vals['Position']); $vals2 = xf_db_fetch_assoc(xf_db_query("select * from PeopleIntl where PersonID=2", $app->db())); $this->assertEquals("Default Position 2", $vals2['Position']); }
function df_translation_warning(&$record, $language = null) { import('Dataface/TranslationTool.php'); $tt = new Dataface_TranslationTool(); $tt->printTranslationStatusAlert($record, $language); }
function save($values) { $res = parent::save($values); import('Dataface/TranslationTool.php'); $tt = new Dataface_TranslationTool(); $tt->setTranslationStatus($this->_record, $this->destinationLanguage, $_POST['__translation__']['status']); return $res; }
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); } } }