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 and Accept solution! Support me! Buy me coffee
- 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.
- Ryviu: Aliexpress Reviews - AliExpress Reviews Importer, one-click import aliexpress reviews, export reviews to CSV file.
- 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 }}
- Helpful? Like and Accept solution! Support me! Buy me coffee
- 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.
- Ryviu: Aliexpress Reviews - AliExpress Reviews Importer, one-click import aliexpress reviews, export reviews to CSV file.
- 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 %}
- Helpful? Like and Accept solution! Support me! Buy me coffee
- 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.
- Ryviu: Aliexpress Reviews - AliExpress Reviews Importer, one-click import aliexpress reviews, export reviews to CSV file.
- 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
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024