You are here

public function LingotekManagementFormBase::downloadTranslations in Lingotek Translation 8.2

Same name and namespace in other branches
  1. 4.0.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::downloadTranslations()
  2. 3.0.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::downloadTranslations()
  3. 3.1.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::downloadTranslations()
  4. 3.2.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::downloadTranslations()
  5. 3.3.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::downloadTranslations()
  6. 3.4.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::downloadTranslations()
  7. 3.5.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::downloadTranslations()
  8. 3.6.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::downloadTranslations()
  9. 3.7.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::downloadTranslations()
  10. 3.8.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::downloadTranslations()

Download translations for a given content in all enabled languages.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity.

File

src/Form/LingotekManagementFormBase.php, line 1292

Class

LingotekManagementFormBase
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

public function downloadTranslations(ContentEntityInterface $entity, $language, $job_id, &$context) {
  $context['message'] = $this
    ->t('Downloading all translations for @type %label.', [
    '@type' => $entity
      ->getEntityType()
      ->getLabel(),
    '%label' => $entity
      ->label(),
  ]);
  if ($profile = $this->lingotekConfiguration
    ->getEntityProfile($entity, FALSE)) {
    $languages = $this->languageManager
      ->getLanguages();
    foreach ($languages as $langcode => $language) {
      if ($langcode !== $entity
        ->language()
        ->getId()) {
        $locale = $this->languageLocaleMapper
          ->getLocaleForLangcode($langcode);
        if ($this->translationService
          ->checkTargetStatus($entity, $locale)) {
          try {
            $this->translationService
              ->downloadDocument($entity, $locale);
          } catch (LingotekApiException $exception) {
            $this
              ->messenger()
              ->addError(t('The download for @entity_type %title translation failed. Please try again.', [
              '@entity_type' => $entity
                ->getEntityTypeId(),
              '%title' => $entity
                ->label(),
            ]));
          }
        }
      }
    }
  }
  else {
    $bundleInfos = $this->entityTypeBundleInfo
      ->getBundleInfo($entity
      ->getEntityTypeId());
    $this
      ->messenger()
      ->addWarning($this
      ->t('The @type %label has no profile assigned so it was not processed.', [
      '@type' => $bundleInfos[$entity
        ->bundle()]['label'],
      '%label' => $entity
        ->label(),
    ]));
  }
}