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 }}
- Solved it? Hit Like and Accept solution! ❤️Buy Me Coffee❤️
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. 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 }}
- Solved it? Hit Like and Accept solution! ❤️Buy Me Coffee❤️
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. 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 %}
- Solved it? Hit Like and Accept solution! ❤️Buy Me Coffee❤️
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. 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
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024