/** * {@inheritdoc} */ public function requestTranslation(JobInterface $job) { $name = "JobID" . $job->id() . '_' . $job->getSourceLangcode() . '_' . $job->getTargetLangcode(); $export = \Drupal::service('plugin.manager.tmgmt_file.format')->createInstance($job->getSetting('export_format')); $path = $job->getSetting('scheme') . '://tmgmt_file/' . $name . '.' . $job->getSetting('export_format'); $dirname = dirname($path); if (file_prepare_directory($dirname, FILE_CREATE_DIRECTORY)) { $file = file_save_data($export->export($job), $path); \Drupal::service('file.usage')->add($file, 'tmgmt_file', 'tmgmt_job', $job->id()); $job->submitted('Exported file can be downloaded <a href="@link">here</a>.', array('@link' => file_create_url($path))); } }
/** * Implements TMGMTFileExportInterface::export(). */ public function export(JobInterface $job, $conditions = array()) { $items = array(); foreach ($job->getItems($conditions) as $item) { $data = \Drupal::service('tmgmt.data')->filterTranslatable($item->getData()); foreach ($data as $key => $value) { $items[$item->id()][$this->encodeIdSafeBase64($item->id() . '][' . $key)] = $value; } } $elements = array('#theme' => 'tmgmt_file_html_template', '#tjid' => $job->id(), '#source_language' => $job->getRemoteSourceLanguage(), '#target_language' => $job->getRemoteTargetLanguage(), '#items' => $items); return \Drupal::service('renderer')->renderPlain($elements); }
/** * {@inheritdoc} */ public function requestTranslation(JobInterface $job) { $tuid = $job->getSetting('translator'); // Create local task for this job. $local_task = tmgmt_local_task_create(array('uid' => $job->getOwnerId(), 'tuid' => $tuid, 'tjid' => $job->id(), 'title' => $job->label())); // If we have translator then switch to pending state. if ($tuid) { $local_task->status = LocalTaskInterface::STATUS_PENDING; } $local_task->save(); // Create task items. foreach ($job->getItems() as $item) { $local_task->addTaskItem($item); } // The translation job has been successfully submitted. $job->submitted(); }
/** * {@inheritdoc} */ public function export(JobInterface $job, $conditions = array()) { $this->job = $job; $this->openMemory(); $this->setIndent(TRUE); $this->setIndentString(' '); $this->startDocument('1.0', 'UTF-8'); // Root element with schema definition. $this->startElement('xliff'); $this->writeAttribute('version', '1.2'); $this->writeAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2'); $this->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $this->writeAttribute('xsi:schemaLocation', 'urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-strict.xsd'); // File element. $this->startElement('file'); $this->writeAttribute('original', 'xliff-core-1.2-strict.xsd'); $this->writeAttribute('source-language', $job->getRemoteSourceLanguage()); $this->writeAttribute('target-language', $job->getRemoteTargetLanguage()); $this->writeAttribute('datatype', 'plaintext'); // Date needs to be in ISO-8601 UTC $this->writeAttribute('date', date('Y-m-d\\Th:m:i\\Z')); $this->startElement('header'); $this->startElement('phase-group'); $this->startElement('phase'); $this->writeAttribute('tool-id', 'tmgmt'); $this->writeAttribute('phase-name', 'extraction'); $this->writeAttribute('process-name', 'extraction'); $this->writeAttribute('job-id', $job->id()); $this->endElement(); $this->endElement(); $this->startElement('tool'); $this->writeAttribute('tool-id', 'tmgmt'); $this->writeAttribute('tool-name', 'Drupal Translation Management Tools'); $this->endElement(); $this->endElement(); $this->startElement('body'); foreach ($job->getItems($conditions) as $item) { $this->addItem($item); } // End the body, file and xliff tags. $this->endElement(); $this->endElement(); $this->endElement(); $this->endDocument(); return $this->outputMemory(); }