-3

I'm creating different copies of my website and each one is in a different language. How to make the website open in the right language according depending on the language of the user? Is it possible in javascript?

  • https://stackoverflow.com/questions/673905/best-way-to-determine-users-locale-within-browser might be useful. – aethercowboy Dec 23 '15 at 21:17
  • You need to provide more details. What have you tried? Where are you stuck? What does your code look like? – SoluableNonagon Dec 23 '15 at 21:18
  • 1
    More importantly. You have the website in various languages by html, but how do you serve the page? Do you use some server-side scripting language? If you can use PHP you can get the HTTP Header Accept-Language and show a page or another based on the information the web browser of the client is sending to you. – Asier Paz Dec 23 '15 at 21:20

1 Answers1

1

To find the language with JS and redirect to that website try this:

var language = (window.navigator.userLanguage || window.navigator.language).split("-")[0];
window.location.href = language + ".example.com";

For me that would output en.example.com, while for others it may say es.example.com (Spanish), ko.example.com (Korean), etc.

Aly
  • 847
  • 1
  • 6
  • 30