You are here

public function LingotekConfigManagementForm::checkTranslationStatus in Lingotek Translation 3.4.x

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

Checks translation status for a given content in a given language.

Parameters

\Drupal\config_translation\ConfigMapperInterface $mapper: The mapper.

string $langcode: The language to check.

File

src/Form/LingotekConfigManagementForm.php, line 1026

Class

LingotekConfigManagementForm
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

public function checkTranslationStatus(ConfigMapperInterface $mapper, $langcode, $job_id, &$context) {
  $context['message'] = $this
    ->t('Checking translation status for %label to language @language.', [
    '%label' => $mapper
      ->getTitle(),
    '@language' => $langcode,
  ]);
  $entity = $mapper instanceof ConfigEntityMapper ? $mapper
    ->getEntity() : NULL;
  $profile = $mapper instanceof ConfigEntityMapper ? $this->lingotekConfiguration
    ->getConfigEntityProfile($entity, FALSE) : $this->lingotekConfiguration
    ->getConfigProfile($mapper
    ->getPluginId(), FALSE);
  $locale = $this->languageLocaleMapper
    ->getLocaleForLangcode($langcode);

  // If there is no entity, it's a config object and we don't abort based on
  // the profile.
  if ($entity === NULL || $profile !== NULL) {
    if ($mapper instanceof ConfigEntityMapper) {
      try {
        $this->translationService
          ->checkTargetStatus($entity, $locale);
      } catch (LingotekApiException $e) {
        $this
          ->messenger()
          ->addError($this
          ->t('%label @locale translation status check failed. Please try again.', [
          '%label' => $entity
            ->label(),
          '@locale' => $locale,
        ]));
      }
    }
    else {
      try {
        $this->translationService
          ->checkConfigTargetStatus($mapper
          ->getPluginId(), $locale);
      } catch (LingotekApiException $e) {
        $this
          ->messenger()
          ->addError($this
          ->t('%label @locale translation status check failed. Please try again.', [
          '%label' => $mapper
            ->getTitle(),
          '@locale' => $locale,
        ]));
      }
    }
  }
  else {
    $this
      ->messenger()
      ->addWarning($this
      ->t('%label has no profile assigned so it was not processed.', [
      '%label' => $mapper
        ->getTitle(),
    ]));
  }
}