skip to Main Content

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

Answers


  1. 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 }}

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search