You are here

protected function Xliff::addTransUnit in Translation Management Tool 8

Adds a single translation unit for a data element.

Parameters

$key: The unique identifier for this data element.

$element: Array with the properties #text and optionally #label.

\Drupal\tmgmt\JobInterface $job: Translation job.

1 call to Xliff::addTransUnit()
Xliff::addItem in translators/tmgmt_file/src/Plugin/tmgmt_file/Format/Xliff.php
Adds a job item to the xml export.

File

translators/tmgmt_file/src/Plugin/tmgmt_file/Format/Xliff.php, line 126

Class

Xliff
Export to XLIFF format.

Namespace

Drupal\tmgmt_file\Plugin\tmgmt_file\Format

Code

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);
  if (isset($element['#max_length'])) {
    $this
      ->writeAttribute('size-unit', 'char');
    $this
      ->writeAttribute('maxwidth', $element['#max_length']);
  }
  $this
    ->startElement('source');
  $this
    ->writeAttribute('xml:lang', $this->job
    ->getRemoteSourceLanguage());
  $this
    ->writeData($element['#text'], $key_array);
  $this
    ->endElement();
  $this
    ->startElement('target');
  $this
    ->writeAttribute('xml:lang', $this->job
    ->getRemoteTargetLanguage());
  if (!empty($element['#translation']['#text'])) {
    $this
      ->writeData($element['#text'], $key_array);
  }
  elseif (!empty($this->configuration['target']) && $this->configuration['target'] === 'source') {
    $this
      ->writeData($element['#text'], $key_array);
  }
  $this
    ->endElement();
  if (isset($element['#label'])) {
    $this
      ->writeElement('note', \Drupal::service('tmgmt.data')
      ->itemLabel($element));
  }
  $this
    ->endElement();
}