On Drupal 8.7.10
How can I get the user's current language code into viewsin a view as a raw value, such as 'en'for example en or 'fr-ca'.fr-ca?
This is notisn't for filtering content. I need the raw value of the users' current language to pass into a urlURL for a third-party tool.
I added a custom text field. Then placed in some twigTwig code. The code is just failing to the fallback 'else'else
value.
Based on other forum posts, I'veI tried it these three ways:this code.
{% if language.getId() == 'en' %}
en
{% elseif language.getId() == 'es-us' %}
es-us
{% elseif language.getId() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}
{% if language.getId() == 'en' %}
en
{% elseif language.getId() == 'es-us' %}
es-us
{% elseif language.getId() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}
I'm getting 'failed'I get failed.
{% if language == 'en' %}
en
{% elseif language == 'es-us' %}
es-us
{% elseif language == 'en-us' %}
en-us
{% else %}
failed
{% endif %}
{% if language == 'en' %}
en
{% elseif language == 'es-us' %}
es-us
{% elseif language == 'en-us' %}
en-us
{% else %}
failed
{% endif %}
I still get 'failed'failed.
{% if language.id() == 'en' %}
en
{% elseif language.id() == 'es-us' %}
es-us
{% elseif language.id() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}
{% if language.id() == 'en' %}
en
{% elseif language.id() == 'es-us' %}
es-us
{% elseif language.id() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}
.... and, I still, 'failed' get the same output.