I have a taxonomy vocabulary with terms.
In a content type, I have a referenced field with this taxonomy.
I can get the taxonomy term in twig like this :
{% for item in node.field_lorem %}
{{ item.entity.label }}
{% endfor %}
It works. But I don't know hot to get the translated terms when I switch language.
All other basic fields are translated. The multilingual configuration seems ok.
Example, a text field {{ content.field_text }}
is translated.
The translation is activated for taxonomy (Taxonomy term is checked).
/admin/config/regional/content-language
The termes are translated :
taxonomy/term/11/translations
Is there something I miss in my twig ? Actually, I always get the terms in default language.
{{ content.field_lorem }}
will be translated as well when you configure the field formatter to display entity labels. In custom code you have to translate the terms yourself, which is probably only possible in PHP, see drupal.stackexchange.com/questions/252957/…{{ content.field_lorem }}
is correctly translated in front-end. I did nothing except{{ content.field_text }}
in twig. The process is different for taxonomy ? Is this because of the referenced field or is it the taxonomy ? I can do it with PHP. I should start with a custom module or can I do it in my-theme.theme ? I will cheek your link, thanks !$node->field_lorem->referencedEntities()
and then translate them like in the linked topic.