Example #1
0
 /**
  * Adds a single translation unit for a data element.
  *
  * @param $key
  *   The unique identifier for this data element.
  * @param $element
  *   Array with the properties #text and optionally #label.
  * @param \Drupal\tmgmt\JobInterface $job
  *   Translation job.
  */
 protected function addTransUnit($key, $element, JobInterface $job)
 {
     $key_array = \Drupal::service('tmgmt.data')->ensureArrayKey($key);
     $this->startElement('trans-unit');
     $this->writeAttribute('id', $key);
     $this->writeAttribute('resname', $key);
     $this->startElement('source');
     $this->writeAttribute('xml:lang', $this->job->getRemoteSourceLanguage());
     if ($job->getSetting('xliff_cdata')) {
         $this->writeCdata(trim($element['#text']));
     } elseif ($job->getSetting('xliff_processing')) {
         $this->writeRaw($this->processForExport($element['#text'], $key_array));
     } else {
         $this->text($element['#text']);
     }
     $this->endElement();
     $this->startElement('target');
     $this->writeAttribute('xml:lang', $this->job->getRemoteTargetLanguage());
     if (!empty($element['#translation']['#text'])) {
         if ($job->getSetting('xliff_processing')) {
             $this->writeRaw($this->processForExport($element['#translation']['#text'], $key_array));
         } else {
             $this->text($element['#translation']['#text']);
         }
     }
     $this->endElement();
     if (isset($element['#label'])) {
         $this->writeElement('note', $element['#label']);
     }
     $this->endElement();
 }
Example #2
0
 /**
  * Helper method to do translation request.
  *
  * @param Job $job
  *   TMGMT Job to be used for translation.
  * @param array|string $q
  *   Text/texts to be translated.
  *
  * @return array
  *   Userialized JSON containing translated texts.
  */
 protected function googleRequestTranslation(Job $job, $q)
 {
     $translator = $job->getTranslator();
     return $this->doRequest($translator, 'translate', array('source' => $job->getRemoteSourceLanguage(), 'target' => $job->getRemoteTargetLanguage(), $this->qParamName => $q), array('headers' => array('Content-Type' => 'text/plain')));
 }