Shopify Request to change section depending on the language's user

245 Views Asked by At

I hope you are doing well. I am working on my Shopify store and I am using a product description through a section that I have created and added to the product.liquid. I am trying to modify the description depending on the language the client is using so it shows the description in a different language.

Here is the code I am using:

    {% if request.host   contains 'storename.com/es' %}
<div class="tienda-questions">
<div class="tienda-questions-product">
...
</div>
</div>

{% endif %}

So the tricky part comes when I use the {% if request.host contains 'storename.com/es' %} When I use the same code based on the product.title the code seems to work perfectly showing the other description in a different language, by using {% if product.title == "product name" %}

I was wondering if anybody has experience with this and knows what request or value could I use to get it right and modify my section according to language.

Thank you for the help in advance!

2

There are 2 best solutions below

0
Vitaliy Dankiv On BEST ANSWER

You can use {{ request.host }} and {{ request.path }} to get full page url, and then usign conditional statement set specific code

{% capture pageUrl %}{{ request.host }}{{ request.path }}{% endcapture %}
{% if pageUrl contains 'storename.com/es' %}
   <div class="tienda-questions">
   <div class="tienda-questions-product">
   ...
   </div>
   </div>

{% endif %}

Also to get customer locale, you can try to get by using {{ request.locale.name }}

0
Alice Girard On

You may try this:

{%- if shop.locale == 'es' -%}
    Doc something
{%- endif -%}

And something more efficient for multiple languages:

{% case shop.locale %}
{% when 'es' %}
    ES content
{% when 'fr' %}
    FR content
{% else %}
    EN content
{% endcase %}

However, usually with multilingual system your product description should be already displayed automatically in the right language so I'm not sure why this kind of code is useful.