Example #1
0
 /**
  * {@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)));
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function checkoutInfo(JobInterface $job)
 {
     $tuid = $job->getSetting('translator');
     if ($tuid && ($translator = User::load($tuid))) {
         $form['job_status'] = array('#type' => 'item', '#title' => t('Job status'), '#markup' => t('Translation job is assigned to %name.', array('%name' => $translator->getUsername())));
     } else {
         $form['job_status'] = array('#type' => 'item', '#title' => t('Job status'), '#markup' => t('Translation job is not assigned to any user.'));
     }
     if ($job->getSetting('job_comment')) {
         $form['job_comment'] = array('#type' => 'item', '#title' => t('Job comment'), '#markup' => Xss::filter($job->getSetting('job_comment')));
     }
     return $form;
 }
Example #3
0
 /**
  * {@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();
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 function checkTranslatable(TranslatorInterface $translator, JobInterface $job)
 {
     if ($job->getSetting('action') == 'not_translatable') {
         return TranslatableResult::no(t('@translator can not translate from @source to @target.', array('@translator' => $job->getTranslator()->label(), '@source' => $job->getSourceLanguage()->getName(), '@target' => $job->getTargetLanguage()->getName())));
     }
     return parent::checkTranslatable($translator, $job);
 }
Example #5
0
 /**
  * Processes trans-unit/target to rebuild back the HTML.
  *
  * @param string $translation
  *   Job data array.
  * @param \Drupal\tmgmt\JobInterface $job
  *   Translation job.
  *
  * @return string
  */
 protected function processForImport($translation, JobInterface $job)
 {
     // In case we do not want to do xliff processing return the translation as
     // is.
     if (!$job->getSetting('xliff_processing')) {
         return $translation;
     }
     $reader = new \XMLReader();
     $reader->XML('<translation>' . $translation . '</translation>');
     $text = '';
     while ($reader->read()) {
         // If the current element is text append it to the result text.
         if ($reader->name == '#text' || $reader->name == '#cdata-section') {
             $text .= $reader->value;
         } elseif ($reader->name == 'x') {
             if ($reader->getAttribute('ctype') == 'lb') {
                 $text .= '<br />';
             }
         } elseif ($reader->name == 'ph') {
             if ($reader->getAttribute('ctype') == 'image') {
                 $text .= '<img';
                 while ($reader->moveToNextAttribute()) {
                     // @todo - we have to use x-html: prefixes for attributes.
                     if ($reader->name != 'ctype' && $reader->name != 'id') {
                         $text .= " {$reader->name}=\"{$reader->value}\"";
                     }
                 }
                 $text .= ' />';
             }
         }
     }
     return $text;
 }