A helper that adds given translation values and sets the source language.
\Drupal\Core\TypedData\TranslatableInterface $entity: The translatable entity.
string $lang_code: The language code.
array $values: An array of translation values.
public function addTranslation(TranslatableInterface $entity, $lang_code, array $values) {
// Add a new translation to the translatable object.
$entity
->addTranslation($lang_code, $values);
// Set the source language for this translation.
$translation = $entity
->getTranslation($lang_code);
$content_translation_manager = \Drupal::service('content_translation.manager');
$content_translation_manager
->getTranslationMetadata($translation)
->setSource($entity
->language()
->getId());
}