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

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.

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.

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.

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.

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.

1 Like

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

4 Likes