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);
}
});