public function LingotekCliService::requestTranslations in Lingotek Translation 3.8.x
Same name and namespace in other branches
- 8.2 src/Cli/LingotekCliService.php \Drupal\lingotek\Cli\LingotekCliService::requestTranslations()
- 4.0.x src/Cli/LingotekCliService.php \Drupal\lingotek\Cli\LingotekCliService::requestTranslations()
- 3.0.x src/Cli/LingotekCliService.php \Drupal\lingotek\Cli\LingotekCliService::requestTranslations()
- 3.1.x src/Cli/LingotekCliService.php \Drupal\lingotek\Cli\LingotekCliService::requestTranslations()
- 3.2.x src/Cli/LingotekCliService.php \Drupal\lingotek\Cli\LingotekCliService::requestTranslations()
- 3.3.x src/Cli/LingotekCliService.php \Drupal\lingotek\Cli\LingotekCliService::requestTranslations()
- 3.4.x src/Cli/LingotekCliService.php \Drupal\lingotek\Cli\LingotekCliService::requestTranslations()
- 3.5.x src/Cli/LingotekCliService.php \Drupal\lingotek\Cli\LingotekCliService::requestTranslations()
- 3.6.x src/Cli/LingotekCliService.php \Drupal\lingotek\Cli\LingotekCliService::requestTranslations()
- 3.7.x src/Cli/LingotekCliService.php \Drupal\lingotek\Cli\LingotekCliService::requestTranslations()
File
- src/
Cli/ LingotekCliService.php, line 100
Class
Namespace
Drupal\lingotek\CliCode
public function requestTranslations($entity_type_id, $entity_id, $langcodes = [
'all',
]) {
$entity = $this
->getEntity($entity_type_id, $entity_id);
if ($entity instanceof EntityInterface) {
$result = [];
$languages = [];
if (in_array('all', $langcodes)) {
$languages = $this->translationService
->requestTranslations($entity);
}
else {
foreach ($langcodes as $langcode) {
$locale = $this->languageLocaleMapper
->getLocaleForLangcode($langcode);
if ($locale) {
$targetAdded = $this->translationService
->addTarget($entity, $locale);
if ($targetAdded) {
$languages[] = $langcode;
}
else {
$this->logger
->error('Language %langcode could not be requested.', [
'%langcode' => $langcode,
]);
}
}
else {
$this->logger
->error('Language %langcode is not valid.', [
'%langcode' => $langcode,
]);
}
}
}
foreach ($languages as $langcode) {
$result[$langcode] = [
'langcode' => $langcode,
];
}
return $result;
}
// Contains an error message.
return $entity;
}