I need to make to redirect the user to another page, in accordance to the language of the browser. For example: if the language of the browser english redirect to site.com/en/.
I try to do like this:
$(document).ready(function () {
var userLang = navigator.language || navigator.userLanguage;
switch (userLang) {
case 'en':
window.location.href = window.location.origin + '/en';
break;
case 'de':
window.location.href = window.location.origin + '/de';
break;
default:
break;
}
});
It's works but the page is constantly reloaded. How to solve it or prompt another solution?