public function LingotekConfigTranslationService::downloadDocument in Lingotek Translation 8
Same name and namespace in other branches
- 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.6.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
boolean TRUE if the document was downloaded successfully, FALSE if not.
Overrides LingotekConfigTranslationServiceInterface::downloadDocument
File
- src/
LingotekConfigTranslationService.php, line 530  - Contains \Drupal\lingotek\LingotekConfigTranslationService.
 
Class
- LingotekConfigTranslationService
 - Service for managing Lingotek configuration translations.
 
Namespace
Drupal\lingotekCode
public function downloadDocument(ConfigEntityInterface $entity, $locale) {
  if ($document_id = $this
    ->getDocumentId($entity)) {
    try {
      $data = $this->lingotek
        ->downloadDocument($document_id, $locale);
    } catch (LingotekApiException $exception) {
      // TODO: log issue
      return FALSE;
    }
    if ($data) {
      // Check the real status, because it may still need review or anything.
      $status = $this->lingotek
        ->getDocumentTranslationStatus($document_id, $locale);
      $langcode = $this->languageLocaleMapper
        ->getConfigurableLanguageForLocale($locale)
        ->getId();
      $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 || $source_status == Lingotek::STATUS_EDITED) {
        $this
          ->setSourceStatus($entity, Lingotek::STATUS_CURRENT);
      }
      if ($status) {
        $this
          ->setTargetStatus($entity, $langcode, Lingotek::STATUS_CURRENT);
      }
      else {
        $this
          ->setTargetStatus($entity, $langcode, Lingotek::STATUS_INTERMEDIATE);
      }
      return TRUE;
    }
  }
  return FALSE;
}