You are here

public function LingotekManagementForm::downloadTranslation in Lingotek Translation 8

Download translation for a given content in a given language.

Parameters

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

string $language: The language to download.

File

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

Class

LingotekManagementForm
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

public function downloadTranslation(ContentEntityInterface $entity, $langcode, &$context) {
  $context['message'] = $this
    ->t('Downloading translation for @type %label in language @language.', [
    '@type' => $entity
      ->getEntityType()
      ->getLabel(),
    '%label' => $entity
      ->label(),
    '@language' => $langcode,
  ]);
  $locale = $this->languageLocaleMapper
    ->getLocaleForLangcode($langcode);
  if ($profile = $this->lingotekConfiguration
    ->getEntityProfile($entity, FALSE)) {
    try {
      $this->translationService
        ->downloadDocument($entity, $locale);
    } catch (LingotekApiException $exception) {
      drupal_set_message(t('The download for @entity_type %title translation failed. Please try again.', array(
        '@entity_type' => $entity
          ->getEntityTypeId(),
        '%title' => $entity
          ->label(),
      )), 'error');
    } catch (LingotekContentEntityStorageException $storage_exception) {
      drupal_set_message(t('The download for @entity_type %title failed because of the length of one field translation value: %table.', array(
        '@entity_type' => $entity
          ->getEntityTypeId(),
        '%title' => $entity
          ->label(),
        '%table' => $storage_exception
          ->getTable(),
      )), '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');
  }
}