Locale in JavaScript?

J

jhurst

But going through the documentation I can't find any reliable way of
getting the locale in JavaScript. Am I missing something, or is this
impossible? If it's impossible, why is it impossible?

It is possible to determine the locale through JavaScript.
For netscape flavored browsers use: navigator.language
For Internet Explorer use: navigator.browserLanguage

That being said, if your goal is to determine the geographical
location of the user, you're better off using an IP->Location library/
service like that offered by Maxmind or Hostip.info

-Joey
 
R

RobG


What do you mean by "locale"? Do you mean timezone? Country?
Approximate geographic location to within say 1,000 km?

Why is it impossible? Because there is no standard that says it must
be available and browser developers have, in general, considered it
unsuitable to include as an extension. As for why they consider it
unsuitable, you'd better ask them.

H'mmm... nasty. No single portable way? Still, better than nothing...
thanks.

Yes, nasty advice - using the language setting is worse than nothing.
Mine says "en-GB", but if you think that means I am in Great Britain,
you're very wrong. My timezone is GMT+10.


The language setting for a browser has no bearing on geographical
location.

Yes, I know I can. I can do lots of things server side. What I want to know
is how to do it client side.

To what level of accuracy? You can determine the timezone, which gets
you within maybe 10 degrees of longitude *if* the user has set it
correctly for the location they are in, but that's it. The language
might give you a clue in regard to latitude, but I doubt it is
reliable at all.

How do you reconcile GMT+8 and en-US?
 
E

Evertjan.

Lee wrote on 26 apr 2007 in comp.lang.javascript:
In your understanding of English, how do you differentiate between
there being a "security issue" and a "security reason"?

You brought up "miscommunication"!

"Issue" can mean many things:
"I have a behavoural issue" could mean "I am a psychopath".
[has nothing to do with the reason, I am sure]
What is the security reason?

The reason for the security.

.... that my locale setting is non of your business,
and not intended to be shown to the web.

Why do you not anwer?

Why do you not anwer?
If the information can be obtained via the browser, by any
means at all, then any restriction set by Javascript is
pointless, isn't it?

It ia as if [the following is just an example] Firefox would he no reason
to implement security, because the security of MSIE is not up to that
standard.

Reasons do not even have to be valid to be used,
not even by javascript engine builders,
as long as they think it is valid and useful.

However if it is as you say with the ability of Java, that you can do
with java what you can nnot do with javascript in a browser, I could, by
switching off java support, be safe from you finding my "locale
settings".

That seems a good enough reason to me for the javascript implementation.
Why are you being such an asshole?

So it is that, having no arguments, you resort to foul language?

So much for spontaneous urges! ;-) ;-)
 
L

Lee

Evertjan. said:
Lee wrote on 26 apr 2007 in comp.lang.javascript:


You brought up "miscommunication"!

Why do you not answer?

"Issue" can mean many things:
"I have a behavoural issue" could mean "I am a psychopath".
[has nothing to do with the reason, I am sure]
What is the security reason?

The reason for the security.

Why do you not answer?

... that my locale setting is non of your business,
and not intended to be shown to the web.

Why not? What is dangerous about knowing your locale?

Why do you not anwer?

I answered below.

Why do you not anwer?

I answered below.

If the information can be obtained via the browser, by any
means at all, then any restriction set by Javascript is
pointless, isn't it?

It ia as if [the following is just an example] Firefox would he no reason
to implement security, because the security of MSIE is not up to that
standard.

No, you're not understanding. The posted said that it is available
in any browser via a Java applet. If it is available in any browser,
then it is pointless to to block it via Javascript, isn't it?

Reasons do not even have to be valid to be used,
not even by javascript engine builders,
as long as they think it is valid and useful.

So, you're suggesting that security is the *excuse*, and that there
is actually no valid reason?


However if it is as you say with the ability of Java, that you can do
with java what you can nnot do with javascript in a browser, I could, by
switching off java support, be safe from you finding my "locale
settings".

That seems a good enough reason to me for the javascript implementation.

Think that through. Can you imagine the designers sitting around
deciding whether to make some information visible, and deciding
that it's ok, because the users can simply disable support for
Java if they don't like it?

So it is that, having no arguments, you resort to foul language?

Which of my arguments did you not understand?

I raised some legitimate questions about your position, and
you resorted to questioning my "urges". If you don't want me
to point out that your logic is flawed, use better logic.
If you don't want me to point out that you're acting like an
asshole, don't act like one.


--
 
E

Evertjan.

Lee wrote on 26 apr 2007 in comp.lang.javascript:
It ia as if [the following is just an example] Firefox would he no
reason to implement security, because the security of MSIE is not up
to that standard.

No, you're not understanding. The posted said that it is available
in any browser via a Java applet. If it is available in any browser,
then it is pointless to to block it via Javascript, isn't it?

Reasons do not even have to be valid to be used,
not even by javascript engine builders,
as long as they think it is valid and useful.

So, you're suggesting that security is the *excuse*, and that there
is actually no valid reason?

I did not. I said that the rweason someone did something does not have to
be valid, if you only ask for the reason.

I think ansd showed the reason is very valid, but that is another story

Think that through. Can you imagine the designers sitting around
deciding whether to make some information visible, and deciding
that it's ok, because the users can simply disable support for
Java if they don't like it?

I do not think you should not close the locks on your home, because the
hedge on the window is faulty.
Which of my arguments did you not understand?

I raised some legitimate questions about your position,

So you maintain "asshole" is legitimate, I end my part in this thread.
 
L

Lee

Evertjan. said:
Lee wrote on 26 apr 2007 in comp.lang.javascript:
It ia as if [the following is just an example] Firefox would he no
reason to implement security, because the security of MSIE is not up
to that standard.

No, you're not understanding. The posted said that it is available
in any browser via a Java applet. If it is available in any browser,
then it is pointless to to block it via Javascript, isn't it?

Reasons do not even have to be valid to be used,
not even by javascript engine builders,
as long as they think it is valid and useful.

So, you're suggesting that security is the *excuse*, and that there
is actually no valid reason?

I did not. I said that the rweason someone did something does not have to
be valid, if you only ask for the reason.

I think ansd showed the reason is very valid, but that is another story

I guess you just don't understand English as well as I thought.


--
 
D

Dr J R Stockton

In comp.lang.javascript message <sYOdnXFcHZ1UabLbnZ2dnUVZ_uSgnZ2d@comcas
Totally off topic, but "return the default locale for this JVM" suffers
from exactly what Randy mentioned above. His default location may not
be his geographical location.


There are two quite distinct concepts involved, each in part known to a
Windows or similar O.S.

There is geographical location. The best that can be done, AFAIK, is to
determine the Winter Time offset from GMT of the assigned locality and
maybe the sign of the latitude. Those settings will usually be correct
for the machine's base location.

There are the cultural settings - date format, currency symbol, decimal
separator. At least some of those are known to, or may be deducible by,
VBScript; and can then be passed on in a web page to javascript, for
those using VBS-compatible browsers.

<script type=text/vbscript>
SSS = CStr(Now)
</script>
<script type=text/javascript>
document.writeln(SSS, "<br>")
document.writeln(new Date().toLocaleString())
</script>

But modification may be needed to make that fail benignly in systems
where it does not work.

For some purposes, the current geographical location is the only
relevant location; for others, the base location is far more significant
- one should not presume that Randy wants the cricket scores just
because he's visiting Barbados, or that the Duke's PA's machine should
necessarily be offered the baseball scores when he's at GSFC.
 
E

Evertjan.

Dr J R Stockton wrote on 26 apr 2007 in comp.lang.javascript:
one should not presume that Randy wants the cricket scores just
because he's visiting Barbados

Still, if you have corroborating evidence like Randy's selfprofessed
preference for blondes, noticeably in a minority on that island, you could.

Distilling web guest's localisations by some clever browsing choices
offered on a page, like local weather and traffic info choices, could be
useful to get a statistical estimate of your visitor's habitad, especially
when correlating it with the visitor's IP.
 

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,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top