Changing language based on the browser locale with manual override option basically?

Hi,

I have a WIX multilingual site in 2 languages and I found this piece of code from a post in the forum that switches the language based on the browser locale - thanks for that to the members responsible for the post.

I tested it with one of my test sites and the code is working, but if the visitor switches the language manually then after the page reloads it switches it back to the browser language.

The question is how can I solve this issue?

An idea is that if the visitor chooses the language manually, then this code should not run. Maybe it would be possible to use the WIX memory storage to save the language selection of the visitors and not run the following code if they choose the language manually?

Can anyone here help me with this and suggest code examples to solve this issue?

Code example I have tested at the moment:

import wixLocation from ‘wix-location’;
import wixWindow from ‘wix-window’;

$w.onReady( function () {
let url = wixLocation.url;
if (url === ‘’) {
setTimeout( function () {
switch (wixWindow.browserLocale) {
case ‘et’:
wixLocation.to(‘ + </?lang=et>’);
break ;
}
}, 1000);
}
// Checks to see if language has already been defined (includes “www”)
else if (url === ‘’){
// Adds a time delay so the visitor anticipates the redirect
setTimeout( function () {
// Checks the browser locale setting
switch (wixWindow.browserLocale) {
// Depending on the locale, redirects to a different page
case ‘et’:
wixLocation.to('<website url> + <?lang=et>');
break ;
}
// The timeout value is 1000 nanoseconds
}, 1000);
}
});

If you use Wix Multilingual, then you shouldn’t need this code as the user can select their own language.
https://support.wix.com/en/wix-multilingual/wix-multilingual-basics

https://support.wix.com/en/article/corvid-tutorial-redirecting-visitors-based-on-browser-language

https://www.wix.com/corvid/forum/community-discussion/auto-detect-language-based-off-browser-solved

If I unterstood right, this code redirects after loading the complite site. This takes several seconds, in my case 5 to 6. Is there a way to redirect before loading the complete site?

Did you ever find an answer to this? I’m also looking for a solution.