Personalized checkout and custom promotions with Shopify Scripts
Hello, I am currently loading an Article dynamically as shown below:
{% assign introductionPath = blog.handle | append: '/introduction' %} {% assign introductionSection = articles[introductionPath] %}
{{ introductionSection.content }} <!-- this shows always the default language -->
although the problem with this approach is that the current locale is completely ignored. Is there any way to rewrite the above script so that I include the current selected locale and load the content with the correct language?
Thank you for the help
Hi @abiratsis
You can refer to this code and check if it works
{% assign introductionPath = blog.handle | append: '/introduction' %}
{% assign introductionSection = articles[introductionPath] %}
{% capture localeContentKey %}{{ introductionPath }}_{{ request.locale | downcase }}{% endcapture %}
{% assign localeContent = introductionSection[localeContentKey] %}
{{ localeContent.content }}
- Helpful? Like & Accept solution! - Support me? Buy me a coffee
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...Sign up now.
Thank you very much for your answer. Apparently, there is another issue with the code, when I try to print out
request.locale.iso_code
I always get the default locale == en. Do you have any clue why is this happening?
You can try to use this code, it will return the name of the locale in the locale itself.
{{ request.locale.endonym_name }}
- Helpful? Like & Accept solution! - Support me? Buy me a coffee
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...Sign up now.
Well ok, that will give me English instead of en, but the problem is that when I change to German I still get en, instead of de
Hi @abiratsis
You can try to use this code to get current locale and check if it works for you
{% if content_for_header %}
{% assign locale_info = content_for_header | split: ',"locale":"' %}
{% assign locale_info = locale_info[1] | split: '","' %}
{% assign current_locale = locale_info[0] %}
Current Locale: {{ current_locale }}
{% endif %}
- Helpful? Like & Accept solution! - Support me? Buy me a coffee
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...Sign up now.
Hello @Dan-From-Ryviu thank you for the answer but that didn't work either.
Let's assume I will manage to extract the current locale from the url, may I ask you where did you get the pattern
{% capture localeContentKey %}{{ introductionPath }}_{{ request.locale.iso_code | downcase }}{% endcapture %}
from? I am asking because when I tried to hardocode the locale this didn't work either. For instance I tried introductionSection['myblog/introduction_en'] and this doesn't work either. So I was wondering if there is a way to get content of an article by specifying locale.
Thank you
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025