0

The following code outputs referenced entities in the original language they were created.

{% for story in node.field_stories %}
  {{ story.entity.label }}
{% endfor %}

I want it to render in the current language (translation) instead. How can I achieve this?

4

Do not use the raw field value, use the render array of the field instead:

{{ content.field_stories }}

This will automatically use the correct language.

NOT RECOMMENDED:
If you have to go the custom, raw value route you can do something like

{% for story in node.field_stories %}
  {% if story.entity.hasTranslation('iso2_langcode') %}
    {{ story.entity.getTranslation('iso2_langcode').label }}
  {% else %}
    {# fallback default lang #}
    {{ story.entity.label }}
  {% endif %}
{% endfor %}
  • Thank you very much - works perfectly! – user94561 Jul 25 '19 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy