public function LingotekConfigTranslationService::downloadDocument in Lingotek Translation 3.6.x
Same name and namespace in other branches
- 8 src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::downloadDocument()
- 8.2 src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::downloadDocument()
- 4.0.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::downloadDocument()
- 3.0.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::downloadDocument()
- 3.1.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::downloadDocument()
- 3.2.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::downloadDocument()
- 3.3.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::downloadDocument()
- 3.4.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::downloadDocument()
- 3.5.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::downloadDocument()
- 3.7.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::downloadDocument()
- 3.8.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::downloadDocument()
Downloads a document from the Lingotek service for a given locale.
Parameters
\Drupal\Core\Config\Entity\ConfigEntityInterface $entity: The entity being downloaded.
string $locale: Lingotek translation language which we want to download.
Return value
bool TRUE if the document was downloaded successfully, FALSE if not.
Overrides LingotekConfigTranslationServiceInterface::downloadDocument
File
- src/
LingotekConfigTranslationService.php, line 755
Class
- LingotekConfigTranslationService
- Service for managing Lingotek configuration translations.
Namespace
Drupal\lingotekCode
public function downloadDocument(ConfigEntityInterface $entity, $locale) {
$profile = $this->lingotekConfiguration
->getConfigEntityProfile($entity);
if ($profile
->id() === Lingotek::PROFILE_DISABLED || $this
->getSourceStatus($entity) === Lingotek::STATUS_CANCELLED) {
return FALSE;
}
if ($document_id = $this
->getDocumentId($entity)) {
$langcode = $this->languageLocaleMapper
->getConfigurableLanguageForLocale($locale)
->getId();
$data = [];
try {
if ($this->lingotek
->getDocumentTranslationStatus($document_id, $locale) !== FALSE) {
$data = $this->lingotek
->downloadDocument($document_id, $locale);
}
else {
return NULL;
}
} catch (LingotekApiException $exception) {
// TODO: log issue
$this
->setTargetStatus($entity, $langcode, Lingotek::STATUS_ERROR);
return FALSE;
}
if ($data) {
// Check the real status, because it may still need review or anything.
$status = $this->lingotek
->getDocumentTranslationStatus($document_id, $locale);
$this
->saveTargetData($entity, $langcode, $data);
// If the status was "Importing", and the target was added
// successfully, we can ensure that the content is current now.
$source_status = $this
->getSourceStatus($entity);
if ($source_status == Lingotek::STATUS_IMPORTING) {
$this
->setSourceStatus($entity, Lingotek::STATUS_CURRENT);
}
if ($source_status == Lingotek::STATUS_EDITED) {
$this
->setTargetStatus($entity, $langcode, Lingotek::STATUS_EDITED);
}
elseif ($status === TRUE) {
$this
->setTargetStatus($entity, $langcode, Lingotek::STATUS_CURRENT);
}
else {
$this
->setTargetStatus($entity, $langcode, Lingotek::STATUS_INTERMEDIATE);
}
return TRUE;
}
}
if ($this
->getSourceStatus($entity) == Lingotek::STATUS_DISABLED) {
$this
->setTargetStatuses($entity, Lingotek::STATUS_DISABLED);
}
return FALSE;
}