Global Content Area, Selective Exclude for Language Switching

Nice solution @JDW , but it means you create a blocs site for japan, and a blocs site for english ( you have 2 .blocs files ) the japan site you upload to yoursite.com/ and the english site you upload to yoursite.com/en/ correct?

@sandy
Correct! I’ve been doing it this way since I started on dual language sites back in 1999. I’ve not any problems doing it that way. the /en subdirectory keeps everything nicely divided.

I also use Google’s Custom Search too, and I can divide the search results by language. So when you search on KIRAMEK: Car Security, Alarms & Auto Speed Locking you get English language results from the English language pages, and the same is true when you search on the Japanese pages.

1 Like

I do this the same way :smiley: also with google search. niceeeee. I will try your ‘trick’ later on a live project.

1 Like

hey @hendon52 I think I asked you this once but I cant find it! To have a multi language page and for people to see the site on their native page its this code you post here right?

The code I posted here is for a language link that can be placed in a global area Can be a button, text or image. You then add an onclick event to the link. You would then add the small piece of code to every page that switches the page to the opposite language version. The url in the code is changed on a page by page basis.

If you want language selection to be automatic, based on the user’s system language, that too can be incorporated by adding a piece of code.

This maybe an option for someone, @Edward can probably comment how well its working for him. Seems to be a few ways you can approach this. I personally haven’t built a multi language site.

I remember you posted this code once! Could you post it again please?

I mean for example if the page its one English and Spanish i will see it on Spanish as my systems its om Spanish and you will see it in English

1 Like

The code below is set up to detect English, German and French. You can add as many languages as needed. Be sure to use the industry-standard ISO language codes which you can find HERE.

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

else if(language == "de" || language == "de-at" || language == "de-li" || language == "de-ch" || language == "de-lu"){
window.location.href = "www.yoursite.com/de";
}

else if(language == “fr” || language == “fr-be” || language == “fr-ch”){
window.location.href = "www.yoursite.com/fr”;
}       
</script>

The above code should ONLY be added to the root index page, not the language variants. This will prevent visitors getting stuck in a loop if they get switched to another language variant of your page. It is also advisable to make a duplicate of the main index page WITHOUT the autodetect code (call it home.html) and have all your home site links point to that version of the home page. Again, this is to prevent visitors getting redirected a second time if they return to your main home page URL.

3 Likes

That was it!! Thank you so much!!

Did you copy and paste @tom2, because there is an error in that code.

hi @PeteSharp

yes I do

could you please tell me the error ? What I have done I delete the fr language

Oh, I think I see the error. Lets try :slight_smile:
UPDATE:

Hi @PeteSharp
shi… Donat work :roll_eyes:

Could you please tell me what you think is the error ?
tom

What error did you see?

The " " are messed up, it’s tricky to spot. Below is the code fixed.

By the way when doing this, a few things you want to consider for SEO.

  1. Make sure you set the lang in the header for each language.
  2. Setup Alternate Meta tags. eg

hreflang attributes

<link rel="alternate" hreflang="fr" href="https://www.yoursite.com/fr/index.html">

You can also use og:locale:alternate
<meta property="og:locale:alternate" content="fr_FR">

The fixed code

<script type="text/javascript">
  var language = window.navigator.language;
  
  if (language == "en-US" || language == "en-GB" || language == "en-CA") {
    window.location.href = "www.yoursite.com/en";
  } else if (language == "de" || language == "de-at" || language == "de-li" || language == "de-ch" || language == "de-lu") {
    window.location.href = "www.yoursite.com/de";
  } else if (language == "fr" || language == "fr-be" || language == "fr-ch") {
    window.location.href = "www.yoursite.com/fr";
  }       
</script>

I think it would be better to do this with .htaccess for the redirects. The alternate tags you really need to add, to stop being penalised by Google.

Hi @PeteSharp

thanks so much. I spotted the " " also :slight_smile:
Do you have an example for a htachess file ? And when I use a htaccess file also set the language on each page ?
What du you mean with the alternate tags ? Where I do this ?

thank you Pete

I suggest doing some research on that part so you understand how it applies. It’s very important if you are making multi language sites.

Same with creating the htaccess entries. Lots of examples online for this stuff.

Oh ok - not sure if I want to do this when it’s difficult with SEO and so on… :slight_smile: I search the www :slight_smile:
Thanks again

Not difficult at all. It’s pretty straight forward. Just need to do some reading on what and how to apply.

I’m just not going to do it all for you :grin:

Not the problem to read it or do it by myself …
but the page is on google first position … and I don´t want to risk that :slight_smile: