protected function Xliff::processForImport in Translation Management Tool 8
Processes trans-unit/target to rebuild back the HTML.
Parameters
string $translation: Job data array.
\Drupal\tmgmt\JobInterface $job: Translation job.
Return value
string
1 call to Xliff::processForImport()
- Xliff::getImportedTargets in translators/
tmgmt_file/ src/ Plugin/ tmgmt_file/ Format/ Xliff.php
File
- translators/
tmgmt_file/ src/ Plugin/ tmgmt_file/ Format/ Xliff.php, line 417
Class
- Xliff
- Export to XLIFF format.
Namespace
Drupal\tmgmt_file\Plugin\tmgmt_file\FormatCode
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;
}