Re: Locale in JavaScript?



On Apr 25, 8:11 pm, Simon Brooke <s...@xxxxxxxxxxxxxx> wrote:
in message <1177473080.796542.163...@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,

jhurs...@xxxxxxxxx ('jhurs...@xxxxxxxxx') wrote:
On Apr 24, 3:13 am, Simon Brooke <s...@xxxxxxxxxxxxxx> wrote:
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?

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.


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.

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.


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.

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?


--
Rob

.



Relevant Pages

  • Re: [SLE] Language selection
    ... > John Summerfield wrote: ... Timezone and locale may be related, ... of UK currency and an Australian timezone relatively difficult: ...
    (SuSE)
  • Re: Post / Zip Code
    ... entry of address that is specific for that locale, ... It might help to identify the country of origin based on the user's IP ... script passed in every query when you can identify the browser on the ... request an address block and then find out later that you need to do ...
    (comp.databases.pick)
  • Re: [SLE] Language selection
    ... Timezone and locale may be related, ... > Your choice of language (for installation) and keyboard would go far ... US-english keyboard for the moment. ...
    (SuSE)
  • Re: daylight savings time
    ... [quoting Chris Dunn] ... Running Debian Testing which is kept up to date. ... sensible choice I have for a locale is en_US.UTF-8. ... Only your timezone info needs to be updated. ...
    (Debian-User)
  • Cant search from www.cookbook.com.
    ... # This is the query file for the query.htm query form. ... # Don't allow more than 300 total hits in the result set. ... # the browser. ... # The locale effects the formatting of dates, times, and numbers. ...
    (microsoft.public.inetserver.indexserver)