How can I display images based on active language in Translation Lab?

Solved

How can I display images based on active language in Translation Lab?

hansen_san
Tourist
7 1 2

Hi Folks,

I have a little problem and couldn't find a workaround yet.

I want to display different images, based on the current active language. Using Translation Lab for Text Translations.

I tried: 

{% if shop_locale.iso_code == 'en' %}
<img>
{% elsif shop_locale.iso_code == 'de' %}

<img>
{% endif %}

also tried with lang=='en'

But none of them worked. What would be the appropriate variable to check ? 

 

Thanks in advance, Hansen

Accepted Solution (1)

Kyle_W
Shopify Partner
179 28 115

This is an accepted solution.

Hi @hansen_san!

If you are wanting to display content based on the user's selected language, then you might have better luck using the request object. For example, you could use something like the following to display content for English users:

{% if request.locale.iso_code == 'en' %}
English content
{% endif %}

 Hopefully this helps!

Kyle W | Helium
Helium builds apps that thousands of merchants depend on:
- Customer Fields ✪✪✪✪✪ (350+ reviews)
- Meteor Mega Menu ✪✪✪✪✪ (250+ reviews)

View solution in original post

Replies 7 (7)

Kyle_W
Shopify Partner
179 28 115

This is an accepted solution.

Hi @hansen_san!

If you are wanting to display content based on the user's selected language, then you might have better luck using the request object. For example, you could use something like the following to display content for English users:

{% if request.locale.iso_code == 'en' %}
English content
{% endif %}

 Hopefully this helps!

Kyle W | Helium
Helium builds apps that thousands of merchants depend on:
- Customer Fields ✪✪✪✪✪ (350+ reviews)
- Meteor Mega Menu ✪✪✪✪✪ (250+ reviews)
hansen_san
Tourist
7 1 2

That works. Thanks a lot ! Very grateful for your help 🙂

Ben1000
Trailblazer
262 3 75

Hi @hansen_san @Kyle_W 

 

I'm using the Dawn 2.0 theme, and I was wondering where do you paste this code?

 

Assuming I want to display different images in my homepage, based on the current active language.

 

Thanks!

hansen_san
Tourist
7 1 2

Hey Ben,

 

I inserted the code in the section liquids where I needed them. I also created some custom sections which I call in my page templates etc. So you need to find the respective section where you want to display your images.

 

Hope this helped you?

Ben1000
Trailblazer
262 3 75

Hi @hansen_san,

 

Can you share parts of screenshots of how you succeedd solving it?

JuliaFr
Tourist
3 1 0

Thank you so much for this! This helped me with an issue I had, and it worked perfectly!

tapita
Shopify Partner
19 0 1

@hansen_san 

This is Max from Tapita. 

We just released the function which can solve your request without coding

https://www.youtube.com/watch?v=w7deZxC72vw

 

Please tell me, I will open a trial for you. 

If our answer is helpful, please give us a Like or mark it as a Solution.