function handle(&$params) { try { $app = Dataface_Application::getInstance(); $query =& $app->getQuery(); $jt = Dataface_JavascriptTool::getInstance(); $jt->import('swete/ui/filter_translations.js'); $app->addHeadContent('<link rel="stylesheet" type="text/css" href="css/swete/actions/review_translations.css"/>'); if (!@$query['-recordid']) { throw new Exception("No record id was specified"); } $record = df_get_record_by_id($query['-recordid']); $job = new SweteJob($record); $tm = XFTranslationMemory::loadTranslationMemoryFor($record, $record->val('source_language'), $record->val('destination_language')); $translations = $job->getTranslations(); $template = 'swete/actions/review_translations.html'; if (@$query['-isDialog']) { $template = 'swete/actions/review_translations_dlg.html'; } df_display(array('job' => $job, 'translations' => $translations), $template); } catch (Exception $e) { if ($e->getCode() == E_USER_ERROR) { echo $e->getMessage(); } else { throw $e; } } }
/** * Tests approve() on a job for a static site, where several strings were added to the job, and some of the strings were translated */ function testApproveStaticString() { $job = SweteJob::createJob($this->staticSite); $username = '******'; //add strings to the job $strings = array("Blah blah blah string", "Doop doop doop doop string", "Whee whee whee whee whee string", "Hey hey hey hey hey strings"); $this->addWebpageForStaticSite($url, $strings); $misses = df_get_records_array('translation_miss_log', array('website_id' => '=' . $this->staticSite->getRecord()->val('website_id'))); foreach ($misses as $miss) { $job->addTranslationMiss($miss->val('translation_miss_log_id')); } $job->compile(); $tm = $job->getTranslationMemory(); $trec = $tm->setTranslationStatus('Blah blah blah string', 'string', XFTranslationMemory::TRANSLATION_SUBMITTED, $username); $trec = $tm->setTranslationStatus('Whee whee whee whee whee string', 'string', XFTranslationMemory::TRANSLATION_SUBMITTED, $username); $this->assertEquals(SweteJob::JOB_STATUS_NEW, $job->getRecord()->val('job_status')); $job->approve('test_user'); $job->refresh(); $this->assertEquals(SweteJob::JOB_STATUS_CLOSED, $job->getRecord()->val('job_status')); foreach ($job->getWebpageRecords() as $webpage) { $tm = XFTranslationMemory::loadTranslationMemoryFor($webpage, $job->getRecord()->val('source_language'), $job->getRecord()->val('destination_language')); $this->assertTrue($tm->containsTranslation('Blah blah blah string', 'string')); $this->assertTrue($tm->containsTranslation('Whee whee whee whee whee string', 'string')); } }
/** * Approves the job, accepting all translations that have been added. */ public function approve($username) { require_once 'modules/tm/lib/XFTranslationMemory.php'; //use import to copy translation memory from the job to the webpages foreach ($this->getWebpageRecords() as $webpage) { $tm = XFTranslationMemory::loadTranslationMemoryFor($webpage, $this->_rec->val('source_language'), $this->_rec->val('destination_language')); $tm->import($this->getTranslationMemory()); } //close the job $this->setStatus(self::JOB_STATUS_CLOSED, $username); }