I am working on a website which needs multilanguage support.
What I did now is creating the structure for it.
I added all the different language sites inside a folder so that I have mysite.com/en, /fr, /it and /de.
Now what I need to do it to redirect the user to its browser language. Means when he is a german user and he lands on mysite.com, he needs to be redirected to mysite.com/de/homepage.
Does anyone form you guys know how to do this in custom code?
I saw a few posts in the forum here, but none really worked. And I dont want to use tools like localizejs which is very bad for SEO.
Copy all the below text into the footer code of the page / site - whichever you want.
The second piece of code does what youâre looking for. However, you will want to use set a cookie just in case the user actually wants to go to the homepage of the English site - otherwise if they try go back there, it will keep redirecting them to the browser language site. Hope that makes sense.
@Diarmuid_Sexton Yeah very nice, and that does also work with the page which is set as homepage in webflow? is it overriding that home page tag somehow?
The thing is, that we can only choose one page as the main homepage of a project, which is of course correct, because Webflow isnât supporting multi-language, yet.
But with multiple languages we should actually have one home page for each language. How you solved this in your projects? Does your code just overrides this and ignores it?
Yes, put this on your English homepage as this is most likely the page that people might type in to their browser and go to directly - i.e. they type mysite.com (which is the english page) but they speak french (so they need to be redirected to the french page)
Otherwise, most likely a search engine will be directing them to your site and for that you need to setup Hreflang for every page - this will tell google what language each page is in.
@Diarmuid_Sexton I just tried it out and it worked. Thank you very much for your help. Just need one last answer I have 4 languages and your code works now for 2. Which part do I need to duplicate for the other 2 languages?
How it works You integrate Weglot via your DNS subdomains (fr.mysite.com for French / de.mysite.com for German), Weglot will detect all your website content and allow you to translate it.
Why itâs SEO optimized
You have a unique URL for each language
The translations are applied âserver-sideâ so the content in the HTML is the translated content
Weglot automatically adds hreflangs to link between all the different translated pages
Weglot detects all your content including metadata, images, alt tab so you can translate everything.
We are new to Webflow so any feedback would be greatly appreciated.
Hi,
I havent found our solution on the forums yet, so I am posting it here.
We are using similar multi-language approach with automatic redirect based on the browser language setting on our website.
In our case, we have separate subfolders for EN and DE versions, where visitor in browser in german is redirected to DE version of the website. However, we ran into a problem when this german user wants to switch back to english , because the language switch button leads to the homepage again, where the user would again be automatically redirected back to the german version of the website.
We solved it by using a language variable stored in browserâs localStorage. On click on the language switcher, we set a constant to the buttons text. And when a user enters the homepage we either:
â send him to the DE page (if the const is not set or if its set to DE AND the browser is in DE)
â or do nothing. (when const is EN or browser is not in german)
All you need is 1 script on homepagehead section:
<script type="text/javascript">
var language = window.navigator.language;
const userLanguage = localStorage.getItem('language');
const isGerman = language == "de" || language == "de-AT" || language == "de-LI" || language == "de-CH" || language == "de-LU";
if(!userLanguage && isGerman){
window.location.href = "/de/home";
} else if(userLanguage == 'de' && isGerman){
window.location.href = "/de/home";
}
One script in âbefore /body tagâ of each subpage:
Hey I have used your solution on my website, and it seems to be working. however I have discovered quite significant lag in loading the website. it takes good 2 second to load it. I have animation on the load and non of them are showing due to the lag. I just winder, did I do something wrong or are there any ettigns which can speed thing up? cheers
Hey guys. For those who donât want to mess a lot, here is the thing:
var lang = navigator.language;
const ls = localStorage.hasOwnProperty(âlanguageStateâ);
if (lang==âuk-UAâ && !ls){
window.location.href = âhttps://www.mysite/uaâ;
localStorage.setItem(âlanguageStateâ, 1);
}
basically, i just needed to redirect the user for the first time visit and that is it. So if the users browser is set to UA and it visit us for the first time, we would redirect him to /ua homepage, but if then he will change locale, etc. We give him the full freedom. Also, the native webflow locale switch work fine, so there is no problem with it.
Enjoy!
ps: for the proper check, run this on console, to get rid of languageState object.
localStorage.removeItem(âlanguageStateâ)