You are here

public function LingotekManagementForm::downloadTranslations in Lingotek Translation 8

Download translations for a given content in all enabled languages.

Parameters

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

File

src/Form/LingotekManagementForm.php, line 896
Contains \Drupal\Lingotek\Form\LingotekManagementForm.

Class

LingotekManagementForm
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

public function downloadTranslations(ContentEntityInterface $entity, $language, &$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);
        try {
          $this->translationService
            ->downloadDocument($entity, $locale);
        } catch (LingotekApiException $exception) {
          drupal_set_message(t('The download for @entity_type %title @locale translation failed. Please try again.', array(
            '@entity_type' => $entity
              ->getEntityTypeId(),
            '%title' => $entity
              ->label(),
            '@locale' => $locale,
          )), 'error');
        }
      }
    }
  }
  else {
    $bundleInfos = $this->entityManager
      ->getBundleInfo($entity
      ->getEntityTypeId());
    drupal_set_message($this
      ->t('The @type %label has no profile assigned so it was not processed.', [
      '@type' => $bundleInfos[$entity
        ->bundle()]['label'],
      '%label' => $entity
        ->label(),
    ]), 'warning');
  }
}