public function LingotekApi::downloadDocument in Lingotek Translation 7.2
Same name and namespace in other branches
- 7.7 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::downloadDocument()
- 7.3 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::downloadDocument()
- 7.4 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::downloadDocument()
- 7.5 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::downloadDocument()
- 7.6 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::downloadDocument()
Downloads the translated document for the specified document and language.
Parameters
int $document_id: The Lingotek document ID that should be downloaded.
string $language_lingotek: A Lingotek language/locale code.
Return value
mixed On success, a SimpleXMLElement object representing the translated document. FALSE on failure.
File
- lib/
Drupal/ lingotek/ LingotekApi.php, line 347 - Defines Drupal\lingotek\LingotekApi
Class
- LingotekApi
- @file Defines Drupal\lingotek\LingotekApi
Code
public function downloadDocument($document_id, $language_lingotek) {
$document = FALSE;
$params = array(
'documentId' => $document_id,
'targetLanguage' => $language_lingotek,
);
if ($results = $this
->request('downloadDocument', $params)) {
try {
// TODO: This is borrowed from the now-deprecated LingotekSession::download()
// and could use refactoring.
$tmpFile = tempnam(file_directory_temp(), 'lingotek');
$fp = fopen($tmpFile, 'w');
fwrite($fp, $results);
fclose($fp);
$text = '';
$file = FALSE;
// downloadDocument returns zip-encoded data.
$zip = new ZipArchive();
$zip
->open($tmpFile);
$name = $zip
->getNameIndex(0);
$file = $zip
->getStream($name);
if ($file) {
while (!feof($file)) {
$text .= fread($file, 2);
}
fclose($file);
}
unlink($tmpFile);
$document = new SimpleXMLElement($text);
} catch (Exception $e) {
watchdog('lingotek', 'Unable to parse downloaded document. Error: @error. Text: !xml.', array(
'!xml' => $text,
'@error' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
}
return $document;
}