You are here

public function TwigExtension::entityTranslation in Twig Tweak 8.2

Returns the translation for the given entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to get the translation from.

string $langcode: (optional) For which language the translation should be looked for, defaults to the current language context.

Return value

\Drupal\Core\Entity\EntityInterface The appropriate translation for the given language context.

File

src/TwigExtension.php, line 1357

Class

TwigExtension
Twig extension with some useful functions and filters.

Namespace

Drupal\twig_tweak

Code

public function entityTranslation(EntityInterface $entity, $langcode = NULL) {
  return \Drupal::service('entity.repository')
    ->getTranslationFromContext($entity, $langcode);
}