detecting user's language?

R

Rex

Hi all,

If I want to detect a user's language, so that I can
change some text to suit them, how do I do that in
Javascript?

Or aren't modern browsers supposed to be able
to cope with more than one language on a page,
separated somehow by language identifiers,
and display only the appropriate text? Maybe
I was dreaming when I read that...

Thanks.
 
B

Bart Van der Donck

Rex said:
If I want to detect a user's language, so that I can
change some text to suit them, how do I do that in
Javascript?

Or aren't modern browsers supposed to be able
to cope with more than one language on a page,
separated somehow by language identifiers,
and display only the appropriate text? Maybe
I was dreaming when I read that...

At least in Microsoft Internet Explorer, you have 3 languages to read
out:

navigator.systemLanguage
navigator.userLanguage
navigator.browserLanguage

If you want to read out the browser's language in a FF/MSIE/NS
compatible manner, you could do something like this:

var lang = 'unknown';
if (navigator.browserLanguage)
lang = navigator.browserLanguage;
if (navigator.language)
lang = navigator.language;
document.write(lang);

Hope this helps,
 
R

Richard Cornford

Bart said:
Not necessarily. You would be using the language setting that the
browser broadcasts anyhow. Of course, there is something to say for
surfers who have disabled javascript in their browser,

And the user's of browsers that do not expose any language information
(and there is no current public standard that says they must).
but that is something that actually applies to almost any post
in this group.

Yes, it is a fundamental issue in Internet browser scripting, which
makes doing what can be done on the server on the sever often the best
advice available in response to javascript questions.

Richard.
 
B

Bart Van der Donck

Richard said:
Bart said:
Not necessarily. You would be using the language setting that the
browser broadcasts anyhow. Of course, there is something to say for
surfers who have disabled javascript in their browser,

And the user's of browsers that do not expose any language information
(and there is no current public standard that says they must).
[...]

I've also seen firewalls that block browser environmental variables, so
they can't reach the web server anyhow.
 
R

Richard Cornford

Bart said:
Richard Cornford wrote:
Not necessarily. You would be using the language setting that the
browser broadcasts anyhow. Of course, there is something to say for
surfers who have disabled javascript in their browser,

And the user's of browsers that do not expose any language information
(and there is no current public standard that says they must).
[...]

I've also seen firewalls that block browser environmental variables, so
they can't reach the web server anyhow.

Blocking Accept-Language wouldn't be the smartest thing for a firewall
to do, as it is to the user's advantage to be served the language of
their preference(s).

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,610
Members
45,255
Latest member
TopCryptoTwitterChannels

Latest Threads

Top