By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,695 Members | 1,580 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,695 IT Pros & Developers. It's quick & easy.

detecting user's language?

P: n/a
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.

Jul 11 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Rex wrote:
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,

--
Bart

Jul 11 '06 #2

P: n/a
Rex wrote:
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?
This is something better handled on the server:
http://www.cs.tut.fi/~jkorpela/multi/index-en.htm

--
David Dorward <http://blog.dorward.me.uk/ <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 11 '06 #3

P: n/a
David Dorward wrote:
Rex wrote:
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?

This is something better handled on the server:
http://www.cs.tut.fi/~jkorpela/multi/index-en.htm
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, but that is
something that actually applies to almost any post in this group.

--
Bart

Jul 12 '06 #4

P: n/a
Bart Van der Donck wrote:
David Dorward wrote:
>Rex wrote:
>>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?

This is something better handled on the server:
http://www.cs.tut.fi/~jkorpela/multi/index-en.htm

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.

Jul 12 '06 #5

P: n/a
Richard Cornford wrote:
Bart Van der Donck wrote:
David Dorward wrote:
Rex wrote:
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?

This is something better handled on the server:
http://www.cs.tut.fi/~jkorpela/multi/index-en.htm
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.

--
Bart

Jul 12 '06 #6

P: n/a
Bart Van der Donck wrote:
Richard Cornford wrote:
<snip>
>>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.

Jul 12 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.