We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Re: shop.locale deprecated

What is the new method to get the language code since shop.locale is deprecated?

Ceri-Waters
Shopify Partner
98 6 30

Hiya,

So {{ shop.locale }} is now deprecated.

What is the correct way to get the lang code to use in the lang="" attribute?

The {{ shop.request.locale }} object doesn't have the language code, it only has the country and language code e.g. en-gb.

Any ideas?

Thanks in Advance,
Ceri.

 

Replies 5 (5)

David_Weru
Shopify Partner
178 16 43

Hello, @Ceri-Waters 

You could use js to grab the browser language and capture it as a liquid variable. Then use a dropdown for the user to change preference.

Below is an example.

https://stackoverflow.com/questions/1043339/javascript-for-detecting-browser-language-preference

 

If you'd like further assistance, please let me know.

Ceri-Waters
Shopify Partner
98 6 30

HI @David_Weru thanks for the response,

{{ shop.locale }} returns the language code of the Shop for the currently selected language (e.g. shopifysite.com/ is english, shopifysite.com/fr/ is French) as opposed to the users browser language.

Kind Regards,

Ceri.

 

David_Weru
Shopify Partner
178 16 43

Hello @Ceri-Waters,

The javascript I linked gets the user's browser language.  

Once you have that, you can use it for example to present your store in the user's language such as the french language store, ect.

Ceri-Waters
Shopify Partner
98 6 30

Thanks for the response again, I'm mainly interested in a Liquid Solution. I want to know what language code is being served by Shopify, as opposed to what's suitable for the user.

 

ziquan
Shopify Partner
1 0 4

I was able to get this accommodated with request.locale.iso_code