Locale in JavaScript?

S

Simon Brooke

I'm working on a system which uses Google maps. I want the user to see a
map of more or less where (s)he is in the world when (s)he first comes to
the system. So the obvious thing seemed to be to have a look-up table of
latitude and longitude against locale, and then use the locale of the
browser...

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?
 
S

Simon Brooke

Randy Webb said:
Simon Brooke said the following on 4/24/2007 6:13 AM:

No, the obvious solution is to ask them where they are in the world and
then show it on the Map.

I don't want to ask them; that's interfering with the immediacy of their
experience of the system. It's worse than a click-through page.
There isn't one as the PC itself doesn't even know where it is in the
world.

The PC knows its locale, however, and the locale is a good enough
approximation for my purposes.
Only way is to ask the user. Otherwise, yes, it is impossible.


It is impossible because it is not possible.

But if I run a Java applet on the same PC, suddenly it's possible. So why
is it possible for an applet but not for Javascript? What is the
architectural choice being made here, and what is it being made for?

Actually that may be the solution - run a single-pixel applet just to get
the locale. But it seems a baroque way to do it.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
e.org.uk>, Tue, 24 Apr 2007 11:13:41, Simon Brooke
I'm working on a system which uses Google maps. I want the user to see a
map of more or less where (s)he is in the world when (s)he first comes to
the system. So the obvious thing seemed to be to have a look-up table of
latitude and longitude against locale, and then use the locale of the
browser...

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?

Standards do not call for it, and it should be easy enough to ask if not
known, store it in a cookie, and have a means of changing the setting.

Until all PCs include Galileo or similar, it's not safe to assume that
the locale setting of the PC matches its geographical whereabouts.

I posses a watch, which is easily enough adjusted by an integer number
of hours or minutes; if I were to take a PC for a trip abroad, I would
use my watch to tell the local time and leave the PC set for UK.

In places which have Summer Time, and when the PC is localised for such
a place, one can tell the Hemisphere (North or South) and the Time Zone,
which gives an idea of the longitude.

See <URL:http://www.merlyn.demon.co.uk/js-date2.htm#SL>.
 
E

Evertjan.

Simon Brooke wrote on 24 apr 2007 in comp.lang.javascript:
But if I run a Java applet on the same PC, suddenly it's possible. So
why is it possible for an applet but not for Javascript? What is the
architectural choice being made here, and what is it being made for?

Actually that may be the solution - run a single-pixel applet just to
get the locale. But it seems a baroque way to do it.

It is spelled out for you: You think you know where Randy is located, but
HikksNotAtHome, as he is expecting a nymphomaniac blonde on an island.
..... Sorry, I'm mixing threads.

It is not possible because browser security won't let you access the most
private parts of the client's operating system.
 
E

Evertjan.

Randy Webb wrote on 24 apr 2007 in comp.lang.javascript:
Now Easter Time Zone would be cool even if my OS does indeed say
Eastern. Sheesh I should proof read sometimes.

Just this local time afternoon I parked my car with GSM-payed-parking in
Rotterdam zone 60, and 10 seconds later, after realizing I had not pressed
the 8 hard enough and after sending an end of parking, I parked in Enschede
zone 8060, some 200 km to the east of Rotterdam.

Somuch for my dual localisation now firmly documented in a police
searchable database, searchable by each traffic cop/warden's pda.
 
L

Lee

Randy Webb said:
IP Address? Nope. Mine will tell you that I am in New York City, New
York in the USA and I could be anywhere from NYC to Bangkok Thailand and
it will tell you the same thing.

For the OP's purposes, the location of the user's proxy seems to
be a reasonable approximation. Most of the relatively few users
with distant proxies should be able to understand what's going on.

Just provide a way to set a home location in a cookie, so it
doesn't become a nuisance.


--
 
J

jhurstus

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?

To determine the local in JavaScript use:
navigator.language for netscape flavored browsers
navigator.browserLanguage for IE

If you want to find out where (approximately) the user is, you're
probably better off using an IP->GeoLocation library/service like
Maxmind or HostIP.

You could also inspect the HTTP "Accept-Language" header in a server
side script.

-Joey
 
L

Lee

Randy Webb said:
Lee said the following on 4/24/2007 8:02 PM:

With 20+ million users (last I checked), are you sure that AOL users
will be able to "understand what's going on"?

I'm sure that AOL users are used to be confused about what's going on.


--
 
S

Simon Brooke

in message <[email protected]>,
To determine the local in JavaScript use:
navigator.language for netscape flavored browsers
navigator.browserLanguage for IE

H'mmm... nasty. No single portable way? Still, better than nothing...
thanks.
If you want to find out where (approximately) the user is, you're
probably better off using an IP->GeoLocation library/service like
Maxmind or HostIP.

You could also inspect the HTTP "Accept-Language" header in a server
side script.

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.
 
S

Simon Brooke

Randy Webb said:
Simon Brooke said the following on 4/24/2007 1:55 PM:

Then you have no way of doing what you are wanting to do.


It does? Please, oh please, tell me what PC/OS setting tells you where I
am located - geographically. I don't believe you.

I didn't say your geographical location, I said your locale. In Windows,
you'll find it in Control Panel/Regional and Language Options.
No it isn't.

So what part of java.util.Locale.getDefault() do you not understand?
Because it isn't possible for an Applet to give you my Geographical
location.

I didn't say your geographical location, I said your locale.
 
S

Simon Brooke

Evertjan. said:
Simon Brooke wrote on 24 apr 2007 in comp.lang.javascript:


It is spelled out for you: You think you know where Randy is located, but
HikksNotAtHome, as he is expecting a nymphomaniac blonde on an island.
.... Sorry, I'm mixing threads.

It is not possible because browser security won't let you access the most
private parts of the client's operating system.

So what part of java.util.Locale.getDefault() do you not understand? Why is
it a security issue in JavaScript (which can, after all, get the
client-side time) but not in Java?

--
(e-mail address removed) (Simon Brooke) http://www.jasmine.org.uk/~simon/
;; Skill without imagination is craftsmanship and gives us
;; many useful objects such as wickerwork picnic baskets.
;; Imagination without skill gives us modern art.
;; Tom Stoppard, Artist Descending A Staircase
 
S

Simon Brooke

Dr J R said:
In comp.lang.javascript message <[email protected]
e.org.uk>, Tue, 24 Apr 2007 11:13:41, Simon Brooke


Standards do not call for it, and it should be easy enough to ask if not
known, store it in a cookie, and have a means of changing the setting.

Until all PCs include Galileo or similar, it's not safe to assume that
the locale setting of the PC matches its geographical whereabouts.

True, and fair enough. But on the whole most users will have their locale
set to somewhere they're familiar with and interested in, even if they
aren't there at the time. Currently everyone who comes to my system sees
an initial map of the UK, and it would really be nicer if French people
saw a map of France, and Australians saw a map of Australia.

Yes, granted an Australian carrying his laptop abroad would almost
certainly still get a map of Australia, but that wouldn't (I hope) be too
surprising, and he can always scroll to where he actually is.
In places which have Summer Time, and when the PC is localised for such
a place, one can tell the Hemisphere (North or South) and the Time Zone,
which gives an idea of the longitude.

See <URL:http://www.merlyn.demon.co.uk/js-date2.htm#SL>.

Yes, timezone is possible... but I'd like to get closer if I can.
 
E

Evertjan.

Simon Brooke wrote on 25 apr 2007 in comp.lang.javascript:
So what part of java.util.Locale.getDefault() do you not understand?

Did I say that? No.
Why is it a security issue in JavaScript (which can, after all, get
the client-side time)

It is if javascript is part of a browser.
but not in Java?

I am not interested in Java, and this NG is about Javascript.
For this part ow your Q look for a Java NG.

Oh wait, perhaps you think that Javascript is the script version of Java?

Do you?
 
S

Simon Brooke

Evertjan. said:
Simon Brooke wrote on 25 apr 2007 in comp.lang.javascript:


Did I say that? No.


It is if javascript is part of a browser.

But JavaScript, in the browser, has exactly the same security issues that
Java, in the browser, has. So why can one do it and the other not? It
isn't a technical issue, since it can be done. It's clearly an
architectural issue, but what I'm trying to understand is what the basis
for the decisions was.
I am not interested in Java, and this NG is about Javascript.
For this part ow your Q look for a Java NG.

Oh wait, perhaps you think that Javascript is the script version of Java?

I've been teaching Java since before the stupid marketing decision to
rename LiveScript to JavaScript happened.

And yes, I'd used LiveScript before it was called JavaScript.
 
E

Evertjan.

Simon Brooke wrote on 25 apr 2007 in comp.lang.javascript:
But JavaScript, in the browser, has exactly the same security issues
that Java, in the browser, has.
Why?

So why can one do it and the other not?
It isn't a technical issue, since it can be done.

Concusion based on the first wrong premise.
If it can be done, it still could be an technical issue.

But I told you ist was a security isue on the part of the browser with
Javascript.

Why it seems to be not with Java, you will have to ask in a Java NG.
It's clearly an architectural issue,

Why clearly?
What is "architectural" in this context?
Do you see security as architectural?
but what I'm trying to understand is what the
basis for the decisions was.

Ask in a Java NG, the Javascript security issue was pointed to by me.
I've been teaching Java since before the stupid marketing decision to
rename LiveScript to JavaScript happened.

So what? You still could have the wrong idea of the combination.

"Yes" on the question that you really think what I surmized?
I'd used LiveScript before it was called JavaScript.

So what? I have used Fortran and Assembler.
 
L

Lee

Evertjan. said:
But I told you ist was a security isue on the part of the browser with
Javascript.

I think there's some miscommunication here.

You've asserted that there is a security issue with Javascript
making the Locale available. It's been pointed out that the
information can already be obtained in other ways, which quite
legitimately calls your assertion into question.

Can you support the assertion that there are security reasons
for not making the Locale setting available via Javascript?


--
 
E

Evertjan.

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


I think there's some miscommunication here.

You've asserted that there is a security issue with Javascript
making the Locale available.

No, I have pointed out or wanted to point out there is a security REASON.

All mentioning of an issue by me I retract, as the word "issue" seems a
source of miscommunication.
It's been pointed out that the
information can already be obtained in other ways,

Not to my satisfaction, since I'm not even interested if there are other
ways to do something outside javascript.

These things are off topic and inconsequential.

Why the "already"?
which quite legitimately calls your assertion into question.

Why?

"It" does not call anything into question, only you do.
You are free to call anything into question, this is usenet.

Do you have spontaneous urges to be "legitimate"?
Can you support the assertion that there are security reasons
for not making the Locale setting available via Javascript?

I never support assertions made by someone else.
Is wanting support another spontaneous urge?

As I said:
I have pointed out or wanted to point out there is a security REASON.

I add:
I did not point out that it was or should be a valid reason.
I think it is a reasonable reason.

That reason does not depend on others implementing
the same in another language.
 
L

Lee

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


No, I have pointed out or wanted to point out there is a security REASON.

In your understanding of English, how do you differentiate between
there being a "security issue" and a "security reason"?

What is the security reason?

Not to my satisfaction, since I'm not even interested if there are other
ways to do something outside javascript.

These things are off topic and inconsequential.

Why the "already"?


Why?

"It" does not call anything into question, only you do.
You are free to call anything into question, this is usenet.

Do you have spontaneous urges to be "legitimate"?

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?

I never support assertions made by someone else.
Is wanting support another spontaneous urge?

Why are you being such an asshole?


--
 
L

-Lost

Simon said:
So what part of java.util.Locale.getDefault() do you not understand? Why is
it a security issue in JavaScript (which can, after all, get the
client-side time) but not in Java?

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.
 
L

-Lost

-Lost said:
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.

Hrmm... after further reading it seems that I am confusing locale with
location.

The second definition at Dictionary dot com threw me.

Nevermind my post.
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top