1

I have a tranlatable node, and I need to get its translation language. You know, I must to know is current node is in Polish or English. So... below there are my devel dumps from a node in Polish and a node in English. I see that there is a difference in #activeLangcode (x-default and en). But how to get that value? Or is there any better way to check current language of node in twig? Please help.

enter image description here

enter image description here

1

1 Answer 1

6

A more elegant Drupal way without typing code:

  1. Go to the Manage display of the content type of your node (/admin/structure/types/manage/YOUR_CONTENT_TYPE/display/full). Select your display mode (or use the default). You will notice the field 'Language', move it to the upper side so it gets out of 'Disabled'.
  2. Once you have done that, the language of the node is available in Twig. You can access the id this way {{ node.langcode.langcode }}; or you can access the whole Object to get other data like the name {{ drupal_dump(node.langcode) }}
2
  • This is the only simple way to get the langcode in <D 10. What a horrible desaster. Shouldn't be that complicated to get it right from the entity. However, thank you so much!
    – Thomas
    Feb 10 at 13:40
  • finally found an answer that fits Drupal 10. thanks
    – Jonatas CD
    Nov 28 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.