Language Detection and Redirect URL

Hi,

I’m looking for an easy way to redirect my website to a specific URL with language detection.

I found this entry form 2014 but it doesn’t help me out:

I’m glad for any help. Thanks.


Here is my public share link: LINK
(how to access public share link)

Hi @aykut

Can you please explain what exactly your trying to do? If you can, I’ll write some updated javascript for you.

Hi @steelesong

I followed your advice and put this code at the footer code. (See picture) Probaply i’ve done something wrong but couldn’t figure it out.

This is what i wrote at the footer code:

It seems like it don’t redirect to the other languages.

Thanks in advance @steelesong

did you include jquery in your project? This javascript relies on jquery

1 Like
var language = window.navigator.language;
if(language == 'en-US'){
    window.location.href = "www.hasaluminyum.com/en"
}

This will work without Jquery. Here is a list where you can find the language codes.

http://www.metamodpro.com/browser-language-codes

My old code might not work anymore. Notice my old code has ‘en’ for english but my browser passed the value ‘en-US’

1 Like

Is this right?

And a last question @steelesong , where and which Jquery snippet i’ve to put in in webflow?

what languages are you trying to hit @aykut ? List them and ill write some vanilla javascript to do it for you. That way you will only have to copy and paste my code

This is really kind of you @steelesong

I want to hit germany (de), Turkey (tr) and English (en)

I’m happy to help.

Please visit this link to confirm it works for you. I’ve tested both english and german and it worked fine

Here is the code

var language = window.navigator.language;
if(language == 'en-US' || language == 'en-AU' || language == 'en-CA')
{
	alert(language);
}

else if(language == 'de' || language == 'de-AT' || language == 'de-LI' || language == 'de-CH' || language == 'de-LU'){
  alert(language);
}

else if(language == 'tr'){
	alert(language);
}

Obviously you will replace the ‘alerts’ with the window.location.href to the appropriate website. This doesn’t rely on Jquery.

2 Likes

Sorry i’m very bad in Jquery.

Is this correct?

Do i’ve to enter something else to the code? To the head code maybe?

@aykut that should work but as I said, you don’t need Jquery to get this to run if you copy the new code that I wrote.

Unless I’m mistaken, Jquery is included in webflow projects by default, so you shouldnt need to do anything else.

<script type='text/javascript'>
var language = window.navigator.language;
if(language == 'en-US' || language == 'en-AU' || language == 'en-CA')
{
window.location.href = 'www.hasaluminyum.com/en'
}

else if(language == 'de' || language == 'de-AT' || language == 'de-LI' || language == 'de-CH' || language      == 'de-LU'){
window.location.href = 'www.hasaluminyum.com/de'
}

else if(language == 'tr'){
window.location.href = 'www.hasaluminyum.com/tr'
}
</script>

Copy my code above. It will work without Jquery.

Hi @steelesong @Waldo

i used exactly the code you written above but the browser always opens the default page.

Thank you anyway @steelesong

Hi @steelesong

Finally i could bring it work. Redirection and language detection works but it permanently refreshes the site from new. So the only thing i can see is the pre loader which plays permanently.

This is the piece of code i used which you shared with me:

<script type= "text/javascript">
var language = window.navigator.language;
  
if(language == "en-US" || language == "en-AU" || language == "en-CA"){
window.location.href = "www.hasaluminyum.com";
}

else if(language == "de" || language == "de-AT" || language == "de-LI" || language == "de-CH" || language == "de-LU"){
window.location.href = "www.hasaluminyum.com";
}

else if(language == "tr"){
window.location.href = "/tr/anasayfa";
}       
</script>

Does the developer console throw any errors?

No. It don’t. Solely the browser redirects the site nearly every 0,2 sec. to the other URL . Ideally it should redirect just once. But it loads in a loop again and again. Couldn’t figure out the issue :confused:

Did you put this code on every version of the site? That would explain why it constantly reloads. Cause it checks the code each time and redirects. Ideally this code should only be ran once. You can achieve this by putting this code on a splash page that loads first, then directs them to the correct website that DOESN’T have this code.

1 Like

Thank you so much for your advice @steelesong

I accidently put it on every site. Now it works.

Thanks again !

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.