/** * {@inheritdoc} */ function requestTranslation(JobInterface $job) { // Add a debug message. $job->addMessage('Test translator called.', array(), 'debug'); // Do something different based on the action, if defined. $action = $job->getSetting('action') ?: ''; switch ($action) { case 'submit': $job->submitted('Test submit.'); break; case 'reject': $job->rejected('This is not supported.'); break; case 'fail': // Target not reachable. $job->addMessage('Service not reachable.', array(), 'error'); break; case 'translate': default: // The dummy translation prefixes strings with the target language. $data = array_filter(\Drupal::service('tmgmt.data')->flatten($job->getData()), array(\Drupal::service('tmgmt.data'), 'filterData')); $tdata = array(); foreach ($data as $key => $value) { if ($job->getTargetLangcode() != $job->getRemoteTargetLanguage()) { $tdata[$key]['#text'] = $job->getTargetLangcode() . '(' . $job->getRemoteTargetLanguage() . '): ' . $value['#text']; } else { $tdata[$key]['#text'] = $job->getTargetLangcode() . ': ' . $value['#text']; } } $job->submitted('Test translation created.'); $job->addTranslatedData(\Drupal::service('tmgmt.data')->unflatten($tdata)); break; } }
/** * {@inheritdoc} */ public function checkoutSettingsForm(array $form, FormStateInterface $form_state, JobInterface $job) { if ($translators = tmgmt_local_assignees($job->getSourceLangcode(), array($job->getTargetLangcode()))) { $form['translator'] = array('#title' => t('Assign job to'), '#type' => 'select', '#options' => array('' => t('- Select user -')) + $translators, '#default_value' => $job->getSetting('translator')); } else { $form['message'] = array('#markup' => t('There are no users available to assign.')); } $form['job_comment'] = array('#type' => 'textarea', '#title' => t('Comment for the translation'), '#description' => t('You can provide a comment so that the assigned user will better understand your requirements.'), '#default_value' => $job->getSetting('job_comment')); return $form; }
/** * {@inheritdoc} */ public function checkTranslatable(TranslatorInterface $translator, JobInterface $job) { // The job is only translatable if the translator is available too. if ($this->checkAvailable($translator)->getSuccess() && array_key_exists($job->getTargetLangcode(), $translator->getSupportedTargetLanguages($job->getSourceLangcode()))) { // We can only translate this job if the target language of the job is in // one of the supported languages. return TranslatableResult::yes(); } return TranslatableResult::no(t('@translator can not translate from @source to @target.', array('@translator' => $translator->label(), '@source' => $job->getSourceLanguage()->getName(), '@target' => $job->getTargetLanguage()->getName()))); }
/** * {@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))); } }