Streaming live at 10am (PST)

Detect Browser Language and Redirect

Hello @Webflow Community,

Do anyone have a simple JS code that I can imbed in my CustomCode, so that:
When the visitor comes to the website,

Any JS wisdom guru ?

Help much much appreciated !!!

2 Likes
<script type="text/javascript">
    $( document ).ready(function(){
        var userLang = navigator.language || navigator.userLanguage;
        if (userLang == "en") {
            break;
        }
        else {
            window.location.href = "www.google.com"
        }
    });
</script>

This should work for you.Replace google with your own domain.

2 Likes

Hello @steelesong,

This looks great,
I’m definitely saving this code for further needs.

Thank you so much for your time and help !!

Your quite welcome sir. Wrote this in college I’ve always referred to it for sites that need language support.

You could as well have used localise.js. https://localizejs.com/blog/2014/05/translate-webflow-website-language/

1 Like

Thanks @topelovely

I’ve finally used LocalizeJS.com and it’s working like a charm !

1 Like

Hi @steelesong this works for 2 languages one of which is english.
In my case, I’ve built a 3 languages site (en, es and ca). Could you please update your answer for this case?

Besides this, I’d like to confirm that Localize.js is a tool that automatically translates your english site to other languages, am I right? But the translation is quite… impersonal, I’m afraid. Thanks for your comments on this as well.

$( document ).ready(function(){
    var userLang = navigator.language || navigator.userLanguage;
    if (userLang == "en") {
        break;
    }
    else if(userLang == "es"){
       window.location.href = "www.facebook.com"
    }
    else if(userLang == "ca"){
       window.location.href = "www.youtube.com"
    }
    else {
        window.location.href = "www.google.com"
    }
});

This should work.
PLEASE NOTE - its showing inconsistent quotations around es and ca. Dont copy and paste this. I dont know why the forums aren’t showing the correct single or double quotation…

Moderator edit: @steelesong I took the liberty to edit your message to fix the quotes.Thank you for posting solutions on the forum.

Hey @steelesong & @jcawoopa!

Have you tried Localize yet? We handle all of this on your behalf, no coding required. Here’s our setup guide for Webflow => https://localizejs.com/docs/integrations/webflow

We make it really easy to translate your Webflow site. Here’s why:

– User-friendly editor to translate or review content.
– Add collaborators to help with the project
– Get real-time quotes from professional translation instantly. Place orders in a click.
– Quick Import/Export of content
– Automatic translation of all updates and changes.

Easy setup – be done in minutes.
Great support – quick response time.
All Languages – even the rare ones!
Free trial – zero risk.
Low cost – affordable for any budget.

Reach out to our support team anytime. We’re happy to help guide you through setup! => Support@LocalizeJS.com

I am going to add mine here for future reference. (Message to future me: Hi!)

Paste this code inside of <script></script> tags in the Before </body> custom code area.

This code means: If browser language is not French (fr) then redirect to [current url]/en/home

$( document ).ready(function(){
var userLang = navigator.language || navigator.userLanguage;
if (userLang != "fr") {
    window.location.href = "en/home"
}
});

#myres

Hello,

Here is the one I use

<script>
$(document).ready(function(){
  var userLang = navigator.language || navigator.userLanguage;
  if (userLang.toLowerCase().includes('fr')) {
      window.location.href = "fr"
  }
});
1 Like

Hi,
I use javascript to get browser language from navigator.language. In Europe we have different sublanguages de-de, de-ch, de-at. If I get language from a PC or Android, everything is correct. If I get it on iOS it always reads de-de.

Does somebody have an idea how to get browser language from iOS Devices?