Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
Hello.
We are translating our store using the GraphiQL API (https://shopify.dev/tutorials/translating-content-for-online-store). Now that we have our content translated we are willing to develop our own language switcher and redirect users accordingly when they use it.
So if our site is shopifystore.com and the user clicks on French in the language switcher we want the page to redirect to to shopifystore.com/fr. We can do this using pure javascript but is there a way to detect current locale url and get the rest of locale urls in liquid? If so, it would be a better solution than having to parse and deal with the actual url in a javascript string.
The "problem" is not dealing with shopifystore.com/lang but with shopifystore.com/lang/products/productname. Also taking into account that the main active language of the store doesn't have the /lang subdirectory. This is why it would be nice if there is already a liquid workaround to access to the locales urls.
Thank you.
Manuel.
@supermanoul You can retrieve the shops locales from Liquid but using JS to get the customer is the correct way to go.
Vix | Developer Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
The way I see it I already have the value in shop_locale. Using JS to retrieve something I already have seems counterproductive to me. Why is it then the correct way to go?
<script>
const urls = {
{% for locale in shop.published_locales %}
{{ iso_code }}: {{ locale.root_url }}
{% endfor %}
};
</script>
Active locale is:
const activeLocale = '{{ request.locale.iso_code }}';
Public Apps | Theme customization & App development
- Was my reply useful? Like it to let me know!
- Did I answer your question? Please mark as Accepted Solution.
- Need more help? Contact us.
Why not just use Shopify.locale for js but use
const activeLocale = '{{ request.locale.iso_code }}';
??
User | RANK |
---|---|
6 | |
5 | |
3 | |
3 | |
3 |