Translations - getting the language used

Hi, is the language used at a given moment in a template, stored in a variable? If yes, what’s the name of this variable?

The reason here is that I’d like to use this variable to build an if/case structure to put whole paragraphs in a capture tag (as translating each piece of text in French and English is rather impractical but also a lot of work).

Thanks!

Hi @Bart

Yes there is.
You can use

{{ locale }}

for this.

Kind regards
Sam

1 Like

Ok thank you Sam, this is a huge help … Would you mind looking at my other question as well (with regard to the translations?

Thanks!

Hi Sam, how can you use this variable ‘locale’ in conditions. For example, I put the language on ‘English’ and put in the following logic:

{% assign str_LanguageUsed = locale %}

{% if str_LanguageUsed == 'en' %}hello{% else %}hallo{% endif %}

But the result is ‘hallo’, not ‘hello’ … what gives? Thanks!

The problem and weird thing is, that locale is also a function.
You can fix your problem by changing

{% assign str_LanguageUsed = locale %}

to

{% capture str_LanguageUsed %}{{locale}}{% endcapture %}

However, I think there’s even a better way to do is and that is by doing the following:

{% t="hello" en:"hello" nl:"hallo" fr:"bonjour" %}
{% assign language %}{{locale}}{% endlocale %}
{% locale language %}{% t"hello" %}{% endlocale %}

Kind regards
Sam

OK great! Thanks Sam