You are here

public function TMGMTFileformatXLIFF::export in Translation Management Tool 7

Return the file content for the job data.

Parameters

$job: The translation job object to be exported.

array $conditions: (optional) An array containing list of conditions.

Return value

String with the file content.

Overrides TMGMTFileFormatInterface::export

File

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

Class

TMGMTFileformatXLIFF
Export to XLIFF format.

Code

public function export(TMGMTJob $job, $conditions = array()) {
  $this->job = $job;
  $this
    ->openMemory();
  $this
    ->setIndent(true);
  $this
    ->setIndentString(' ');
  $this
    ->startDocument('1.0', 'UTF-8');

  // Root element with schema definition.
  $this
    ->startElement('xliff');
  $this
    ->writeAttribute('version', '1.2');
  $this
    ->writeAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
  $this
    ->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  $this
    ->writeAttribute('xsi:schemaLocation', 'urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-strict.xsd');

  // File element.
  $this
    ->startElement('file');
  $this
    ->writeAttribute('original', 'xliff-core-1.2-strict.xsd');
  $this
    ->writeAttribute('source-language', $job
    ->getTranslator()
    ->mapToRemoteLanguage($job->source_language));
  $this
    ->writeAttribute('target-language', $job
    ->getTranslator()
    ->mapToRemoteLanguage($job->target_language));
  $this
    ->writeAttribute('datatype', 'plaintext');

  // Date needs to be in ISO-8601 UTC
  $this
    ->writeAttribute('date', date('Y-m-d\\Th:m:i\\Z'));
  $this
    ->startElement('header');
  $this
    ->startElement('phase-group');
  $this
    ->startElement('phase');
  $this
    ->writeAttribute('tool-id', 'tmgmt');
  $this
    ->writeAttribute('phase-name', 'extraction');
  $this
    ->writeAttribute('process-name', 'extraction');
  $this
    ->writeAttribute('job-id', $job->tjid);
  $this
    ->endElement();
  $this
    ->endElement();
  $this
    ->startElement('tool');
  $this
    ->writeAttribute('tool-id', 'tmgmt');
  $this
    ->writeAttribute('tool-name', 'Drupal Translation Management Tools');
  $this
    ->endElement();
  $this
    ->endElement();
  $this
    ->startElement('body');
  foreach ($job
    ->getItems($conditions) as $item) {
    $this
      ->addItem($item);
  }

  // End the body, file and xliff tags.
  $this
    ->endElement();
  $this
    ->endElement();
  $this
    ->endElement();
  $this
    ->endDocument();
  return $this
    ->outputMemory();
}