You are here

protected function TMGMTFileformatXLIFF::processForImport in Translation Management Tool 7

Processes trans-unit/target to rebuild back the HTML.

Parameters

string $translation: Job data array.

TMGMTJob $job: Translation job.

Return value

string

1 call to TMGMTFileformatXLIFF::processForImport()
TMGMTFileformatXLIFF::getImportedTargets in translators/file/tmgmt_file.format.xliff.inc

File

translators/file/tmgmt_file.format.xliff.inc, line 362

Class

TMGMTFileformatXLIFF
Export to XLIFF format.

Code

protected function processForImport($translation, TMGMTJob $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;
}