Adds a single translation unit for a data element.
$key: The unique identifier for this data element.
$element: Array with the properties #text and optionally #label.
\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);
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();
}