function lingotek_operation_content_download in Lingotek Translation 8
Same name and namespace in other branches
- 8.2 lingotek.batch.inc \lingotek_operation_content_download()
- 4.0.x lingotek.batch.inc \lingotek_operation_content_download()
- 3.0.x lingotek.batch.inc \lingotek_operation_content_download()
- 3.1.x lingotek.batch.inc \lingotek_operation_content_download()
- 3.2.x lingotek.batch.inc \lingotek_operation_content_download()
- 3.3.x lingotek.batch.inc \lingotek_operation_content_download()
- 3.4.x lingotek.batch.inc \lingotek_operation_content_download()
- 3.5.x lingotek.batch.inc \lingotek_operation_content_download()
- 3.6.x lingotek.batch.inc \lingotek_operation_content_download()
- 3.7.x lingotek.batch.inc \lingotek_operation_content_download()
- 3.8.x lingotek.batch.inc \lingotek_operation_content_download()
Wrapper function for running content downloads.
File
- ./
lingotek.batch.inc, line 89 - Lingotek batch functions
Code
function lingotek_operation_content_download($entity_type, $entity_id, $locale, &$context) {
if ($context) {
$context['message'] = t('Downloading translation "@locale" for @entity_type #@entity_id', array(
'@entity_type' => $entity_type,
'@entity_id' => $entity_id,
'@locale' => $locale,
));
}
/** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
$translation_service = \Drupal::service('lingotek.content_translation');
// Prepare the entity's translatable content for upload.
$entity = entity_load($entity_type, $entity_id);
try {
if ($translation_service
->downloadDocument($entity, $locale)) {
$context['results']['downloads'] = !empty($context['results']['downloads']) ? $context['results']['downloads'] + 1 : 1;
}
else {
$context['results']['error'][] = t('The download for @entity_type %title failed. Please try again.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
));
}
} catch (LingotekApiException $exception) {
$context['results']['error'][] = t('The download for @entity_type %title failed. Please try again.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
));
}
}