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.

3 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. Localize: Website and App Translation Platform

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.

1 Like

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 => How to easily translate Webflow websites - Localize Integration Tutorial

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

2 Likes

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"
  }
});
2 Likes

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?

1 Like

hi John,
did you manage to find a solution?

Hey Localize team!

I wanted to check out your solution, but I have to disagree with your “low cost — affordable for any budget” statement — your product’s pricing is nowhere near low cost or affordable.

Is $60/month (insane!) affordable for you?

You could counter my reply by saying two things:

  1. Our target audience is people from first world countries, specifically the US.

  2. We offer a ton of features on the cheapest plan.

Then I’ll counter that too:

  1. Creating a translation product for the US only is stupid. If you wanted to say about the pricing being affordable for US citizens, then I highly doubt that US citizens will consider $60 cheap.

  2. I didn’t dive too deep in your pricing model because it’s enough to see that the cheapest plan offers only 1 language (except site’s main/default language). $60 for one language? Seriously?

Maybe your product is really superb, maybe it’s even easy to implement and configure, and many other maybes — but it’s definitely not cheap and affordable by any means.

P.S: No offense, not all of my clients are from the US — I don’t earn a shitload of money to afford Localize.js for my personal projects. Though, I will one day offer it to one of my clients who will feel comfortable with me testing it.