You are here

public function LingotekManagementForm::requestTranslation in Lingotek Translation 8

Request translations 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 842
Contains \Drupal\Lingotek\Form\LingotekManagementForm.

Class

LingotekManagementForm
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

public function requestTranslation(ContentEntityInterface $entity, $langcode, &$context) {
  $context['message'] = $this
    ->t('Requesting translation for @type %label to 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
        ->addTarget($entity, $locale);
    } catch (LingotekApiException $exception) {
      drupal_set_message(t('The request for @entity_type %title translation failed. Please try again.', array(
        '@entity_type' => $entity
          ->getEntityTypeId(),
        '%title' => $entity
          ->label(),
      )), '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');
  }
}