Pk’s Diary: Accessing Translated Entity in Views Twig | Drupal 8

Accessing Translated Entity in Views Twig | Drupal 8
purushotam
Tue, 07/13/2021 – 01:49

Though ideally if we use the views correctly and override them well, Drupal Views itself take care of getting the translated version as per configurations of the view. For details check this: EntityField::getValue

But if somehow we wanna get translated version of the entity in a views twig, we will have to get the current language and then call ContentEntityBase::getTranslation on the entity of the views row. And there are various ways of getting the current language in the views-view.html.twig:

#1 Use preprocess to add current language


Go to Source
Author: