public function LingotekConfigManagementForm::requestTranslation in Lingotek Translation 3.3.x
Same name and namespace in other branches
- 8 src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::requestTranslation()
- 8.2 src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::requestTranslation()
- 4.0.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::requestTranslation()
- 3.0.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::requestTranslation()
- 3.1.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::requestTranslation()
- 3.2.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::requestTranslation()
- 3.4.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::requestTranslation()
- 3.5.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::requestTranslation()
- 3.6.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::requestTranslation()
- 3.7.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::requestTranslation()
- 3.8.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::requestTranslation()
Request translations for a given content in a given language.
Parameters
\Drupal\config_translation\ConfigMapperInterface $mapper: The mapper.
string $langcode: The language to download.
File
- src/
Form/ LingotekConfigManagementForm.php, line 1070
Class
- LingotekConfigManagementForm
- Form for bulk management of content.
Namespace
Drupal\lingotek\FormCode
public function requestTranslation(ConfigMapperInterface $mapper, $langcode, $job_id, &$context) {
$context['message'] = $this
->t('Requesting translation for %label to language @language.', [
'%label' => $mapper
->getTitle(),
'@language' => $langcode,
]);
$locale = $this->languageLocaleMapper
->getLocaleForLangcode($langcode);
$entity = $mapper instanceof ConfigEntityMapper ? $mapper
->getEntity() : NULL;
$profile = $mapper instanceof ConfigEntityMapper ? $this->lingotekConfiguration
->getConfigEntityProfile($entity, FALSE) : $this->lingotekConfiguration
->getConfigProfile($mapper
->getPluginId(), FALSE);
// 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
->addTarget($entity, $locale);
} catch (LingotekPaymentRequiredException $exception) {
$this
->messenger()
->addError(t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
} catch (LingotekDocumentArchivedException $exception) {
$this
->messenger()
->addError(t('Document @entity_type %title has been archived. Please upload again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
} catch (LingotekDocumentLockedException $exception) {
$this
->messenger()
->addError(t('Document @entity_type %title has a new version. The document id has been updated for all future interactions. Please try again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
} catch (LingotekApiException $e) {
$this
->messenger()
->addError($this
->t('Document @entity_type %title @locale translation request failed. Please try again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
'@locale' => $locale,
]));
}
}
else {
try {
$this->translationService
->addConfigTarget($mapper
->getPluginId(), $locale);
} catch (LingotekPaymentRequiredException $exception) {
$this
->messenger()
->addError(t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
} catch (LingotekDocumentArchivedException $exception) {
$this
->messenger()
->addError(t('Document %label has been archived. Please upload again.', [
'%label' => $mapper
->getTitle(),
]));
} catch (LingotekDocumentLockedException $exception) {
$this
->messenger()
->addError(t('Document %label has a new version. The document id has been updated for all future interactions. Please try again.', [
'%label' => $mapper
->getTitle(),
]));
} catch (LingotekApiException $e) {
$this
->messenger()
->addError($this
->t('Document %label @locale translation request 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(),
]));
}
}