Processes trans-unit/target to rebuild back the HTML.
string $translation: Job data array.
\Drupal\tmgmt\JobInterface $job: Translation job.
string
protected function processForImport($translation, JobInterface $job) {
// In case we do not want to do xliff processing return the translation as
// is.
if (!$job
->getSetting('xliff_processing')) {
return $translation;
}
$reader = new \XMLReader();
$reader
->XML('<translation>' . $translation . '</translation>');
$text = '';
while ($reader
->read()) {
// If the current element is text append it to the result text.
if ($reader->name == '#text' || $reader->name == '#cdata-section') {
$text .= $reader->value;
}
elseif ($reader->name == 'x') {
if ($reader
->getAttribute('ctype') == 'lb') {
$text .= '<br />';
}
}
elseif ($reader->name == 'ph') {
if ($reader
->getAttribute('ctype') == 'image') {
$text .= '<img';
while ($reader
->moveToNextAttribute()) {
// @todo - we have to use x-html: prefixes for attributes.
if ($reader->name != 'ctype' && $reader->name != 'id') {
$text .= " {$reader->name}=\"{$reader->value}\"";
}
}
$text .= ' />';
}
}
}
return $text;
}