You are here

public function I18n::getTranslation in Bamboo Twig 8.4

Same name and namespace in other branches
  1. 8.5 bamboo_twig_i18n/src/TwigExtension/I18n.php \Drupal\bamboo_twig_i18n\TwigExtension\I18n::getTranslation()
  2. 8.3 bamboo_twig_i18n/src/TwigExtension/I18n.php \Drupal\bamboo_twig_i18n\TwigExtension\I18n::getTranslation()

Gets a translation of the entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to translate.

string|null $langcode: (optional) The language code of the translation to get. NULL (default) means to use the user interface language for the page.

Return value

\Drupal\Core\Entity\EntityInterface An entity object when translations exists or the original entity.

File

bamboo_twig_i18n/src/TwigExtension/I18n.php, line 102

Class

I18n
Provides some 'Internationalization' Twig Extensions.

Namespace

Drupal\bamboo_twig_i18n\TwigExtension

Code

public function getTranslation(EntityInterface $entity, $langcode = NULL) {
  $entityRepository = $this
    ->getEntityRepository();
  if (!$langcode) {
    $langcode = $this
      ->getCurrentLanguage();
  }
  return $entityRepository
    ->getTranslationFromContext($entity, $langcode);
}