/** * {@inheritdoc} */ public function checkoutSettingsForm(array $form, FormStateInterface $form_state, JobInterface $job) { if ($job->getTranslator()->getSetting('expose_settings')) { $form['action'] = array('#type' => 'select', '#title' => t('Action'), '#options' => array('translate' => t('Translate'), 'submit' => t('Submit'), 'reject' => t('Reject'), 'fail' => t('Fail'), 'not_available' => t('Not available'), 'not_translatable' => t('Not translatable')), '#default_value' => $job->getTranslator()->getSetting('action')); } return $form; }
/** * {@inheritdoc} */ public function checkoutSettingsForm(array $form, FormStateInterface $form_state, JobInterface $job) { if ($job->getTranslator()->getSetting('allow_override')) { $form['export_format'] = array('#type' => 'radios', '#title' => t('Export to'), '#options' => \Drupal::service('plugin.manager.tmgmt_file.format')->getLabels(), '#default_value' => $job->getTranslator()->getSetting('export_format'), '#description' => t('Please select the format you want to export data.')); } return parent::checkoutSettingsForm($form, $form_state, $job); }
/** * {@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); }
/** * Provides a simple wrapper for the checkout info fieldset. * * @param \Drupal\tmgmt\JobInterface $job * Translation job object. * @param $form * Partial form structure to be wrapped in the fieldset. * * @return * The provided form structure wrapped in a collapsed fieldset. */ public function checkoutInfoWrapper(JobInterface $job, $form) { $label = $job->getTranslator()->label(); $form += array('#title' => t('@translator translation job information', array('@translator' => $label)), '#type' => 'details', '#open' => FALSE); return $form; }
/** * {@inheritdoc} */ public function requestTranslation(JobInterface $job) { // Pull the source data array through the job and flatten it. $data = \Drupal::service('tmgmt.data')->filterTranslatable($job->getData()); $translation = array(); foreach ($data as $key => $value) { // Query the translator API. try { $result = $this->doRequest($job->getTranslator(), 'Translate', array('from' => $job->getRemoteSourceLanguage(), 'to' => $job->getRemoteTargetLanguage(), 'contentType' => 'text/plain', 'text' => $value['#text']), array('Content-Type' => 'text/plain')); // Lets use DOMDocument for now because this service enables us to // send an array of translation sources, and we will probably use // this soon. $dom = new \DOMDocument(); $dom->loadXML($result->getBody()->getContents()); $items = $dom->getElementsByTagName('string'); $translation[$key]['#text'] = $items->item(0)->nodeValue; // The translation job has been successfully submitted. $job->submitted('The translation job has been submitted.'); // Save the translated data through the job. $job->addTranslatedData(\Drupal::service('tmgmt.data')->unflatten($translation)); } catch (RequestException $e) { $job->rejected('Rejected by Microsoft Translator: !error', array('!error' => $e->getResponse()->getBody()->getContents()), 'error'); } } }
/** * {@inheritdoc} */ public function hasCheckoutSettings(JobInterface $job) { return $job->getTranslator()->getSetting('allow_override'); }
/** * Helper function for retrieving the rendered job checkout information. */ function checkoutInfo(JobInterface $job) { // The translator might have been disabled or removed. if (!$job->hasTranslator()) { return array('#markup' => t('The job has no provider assigned.')); } $translator = $job->getTranslator(); $plugin_ui = $this->translatorManager->createUIInstance($translator->getPluginId()); return $plugin_ui->checkoutInfo($job); }