You are here

public function LingotekConfigTranslationService::addTarget in Lingotek Translation 8

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

Request a translation for a given entity in the given locale.

Parameters

\Drupal\Core\Config\Entity\ConfigEntityInterface $entity: The entity which target we want to add.

string $locale: Lingotek translation language which we want to modify.

Overrides LingotekConfigTranslationServiceInterface::addTarget

File

src/LingotekConfigTranslationService.php, line 418
Contains \Drupal\lingotek\LingotekConfigTranslationService.

Class

LingotekConfigTranslationService
Service for managing Lingotek configuration translations.

Namespace

Drupal\lingotek

Code

public function addTarget(ConfigEntityInterface &$entity, $locale) {
  if ($locale == $this->languageLocaleMapper
    ->getLocaleForLangcode($entity
    ->language()
    ->getId())) {

    // We don't want to translate from one language to itself.
    return FALSE;
  }
  if ($document_id = $this
    ->getDocumentId($entity)) {
    $source_status = $this
      ->getSourceStatus($entity);
    $current_status = $this
      ->getTargetStatus($entity, $this->languageLocaleMapper
      ->getConfigurableLanguageForLocale($locale)
      ->getId());
    if ($current_status !== Lingotek::STATUS_PENDING && $current_status !== Lingotek::STATUS_CURRENT && $current_status !== Lingotek::STATUS_READY) {
      if ($this->lingotek
        ->addTarget($document_id, $locale, $this->lingotekConfiguration
        ->getConfigEntityProfile($entity))) {
        $this
          ->setTargetStatus($entity, $this->languageLocaleMapper
          ->getConfigurableLanguageForLocale($locale)
          ->getId(), Lingotek::STATUS_PENDING);

        // If the status was "Importing", and the target was added
        // successfully, we can ensure that the content is current now.
        if ($source_status == Lingotek::STATUS_IMPORTING) {
          $this
            ->setSourceStatus($entity, Lingotek::STATUS_CURRENT);
        }
        return TRUE;
      }
    }
  }
  return FALSE;
}