Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the browser language with Javascript

I want to access the user browser settings and change the browser language, is this possible using Javascript?

If it's possible, how can I access this? (sample code please)

like image 428
ammar Avatar asked Sep 20 '10 17:09

ammar


People also ask

How do I get user browser language?

To get the user's locale in the browser, access the first element of the languages property on the navigator object, e.g. navigator. languages[0] . The property returns an array of strings that represent the user's preferred languages.

How can I get browser language in jquery?

Go to the settings -> Scroll down to and click "Show advanced settings..." -> Click "Language and input settings..." -> Then select you're desired language, click done and restart your browser.


1 Answers

You can detect, but cannot set.

var lang = navigator.language || navigator.userLanguage;

// navigator.language     : Netscape & Firefox
// navigator.userLanguage : Internet Explorer


If you want to output different languages, the best way is to do it server-side. Either:

  • use an AJAX call to dynamically load the appropriate page
  • use a session variable to load the initial page correctly
like image 197
vol7ron Avatar answered Oct 02 '22 15:10

vol7ron