Change website language to browser's language automatically

1 reply · opened Oct 31, 2021

MmervezoeOct 31, 2021

Hi there,

I really liked these templates, very conceptive, thanks a lot for this in advanced.
I'm using demo-medical and already have the language dropdown menu but actually I don't know how to detect browser's language to open the website in that language. Is there any written code about this in canvas? Or can you tell me how can I make this happen?

Cheers!

SSemicolon WebSTAFFNov 1, 2021

Hello,

Thanks so much for the Kind Words! :)

You can consider using the following JS Code and redirect the Page based on the Language:
[ch_pre type="js"]<script type="text/javascript">
var userLang = navigator.language || navigator.userLanguage;

if( userLang == 'en-US' ) {
window.location.href = "http://www.your-website.com/en";
} else {
window.location.href = "http://www.your-website.com/fr";
}
</script>[/ch_pre]

This will definitely work fine. Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard