I guess anyone who wants to use a code option, a simple alternative is to add a small piece of code on every one of your pages, something on the lines of this
<script>
function langSwitch() {
window.open("https://YourSite.com/oppositeLanguagePage.html");
}
</script>
You would just change the url to switch to the appropriate page in the opposite language. I guess you could even use relative URLS
To make the language switcher work, you only have to add a global onclick attribute to the language link
onclick = langSwitch ();
Because the link is in the global area, you only have to add this once - (maybe twice - once for each language version of the site).
So, although the link is targeting the same function globally, the fact that the function is unique to every page means that you can have a unique URL on each page.
Thank you for mentioning that. I wonāt be using it on my sites though because I absolutely hate it when I visit a site from Japan and it switches me to Japanese even though I want English, forcing me to manually click the English link to get the correct language. The way I have our sites setup, what they see is what they get, and if the dislike it, they click the language switcher link. Thatās what I like personally, so Iāve set it up that way. Because we are based in Japan, the root urls default to Japanese, so itās not like folks will see the wrong language by accident. And because our sites have been around a long while, when people search for English terms on Google, they tend to get shown our English pages, not the Japanese. So it all works rather well. But again, they key to my success was the code that replaces the link so I can keep my beloved links in the global Header and Footer area. Thatās golden in my eyes!
Yep. There are some pages Iāve not rebuilt in Blocs yet and probably wonāt if they are in Japan exclusive things like Events. Iāve tried to mark most of the pages I will eventually translate with a Japanese flag emoji to help alert people. The Events page is just one exception to that.
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.
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.
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.
thanks so much. I spotted the " " also
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 ?