You are here

public function LingotekCliService::downloadTranslations in Lingotek Translation 3.1.x

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

File

src/Cli/LingotekCliService.php, line 160

Class

LingotekCliService

Namespace

Drupal\lingotek\Cli

Code

public function downloadTranslations($entity_type_id, $entity_id, $langcodes = [
  'all',
]) {
  $entity = $this
    ->getEntity($entity_type_id, $entity_id);
  if ($entity instanceof EntityInterface) {
    if (in_array('all', $langcodes)) {
      $this->translationService
        ->downloadDocuments($entity);
    }
    else {
      foreach ($langcodes as $langcode) {
        $locale = $this->languageLocaleMapper
          ->getLocaleForLangcode($langcode);
        if ($locale) {
          $this->translationService
            ->downloadDocument($entity, $locale);
        }
        else {
          $this->logger
            ->error($this
            ->t('Language %langcode is not valid.', [
            '%langcode' => $langcode,
          ]));
        }
      }
    }
    return self::COMMAND_SUCCEDED;
  }

  // Contains an error message.
  return $entity;
}