knowing where the user comes from

M

microgolf

Hey, i have a question.
i'm about to run an multilangual (if that even is a word) site and i
would
like to adjust the language of the site depending on what region
the user lives... is there a way to know?

thanks in advance,
microgolf
 
J

Joost Diepenmaat

microgolf said:
Hey, i have a question.
i'm about to run an multilangual (if that even is a word) site and i
would
like to adjust the language of the site depending on what region
the user lives... is there a way to know?

There are ways to determine the user's location (with more or less
precision) based on his IP address. On the other hand, it would be
better to just use the user's language preference instead of his
location. Conveniently, the language preference is send to the server
at each request. On the third hand, most users never change their
language preference (though local vendors may have set it for them).

See, for example:
http://www.w3.org/International/questions/qa-accept-lang-locales

Which isn't really about language, but does touch on most of the
relevant issues.
 
D

Dr J R Stockton

In comp.lang.javascript message <d70ff805-94df-4a01-8aeb-5cd0d884acbe@m7
3g2000hsh.googlegroups.com>, Fri, 6 Jun 2008 11:05:21, microgolf
i'm about to run an multilangual (if that even is a word) site and i
would
like to adjust the language of the site depending on what region
the user lives... is there a way to know?

The place where the user is, the place where the user lives, and the
place where the user comes from, and the places where the user's
preferred language originated or is common, are not necessarily the
same. And the computer is not necessarily set to the local language.

Consider a hypothetical Ambassador to Poland who was born in Korea and
is visiting the residence of the French Ambassador to Bulgaria, and who
wants to read about a baseball game.

To find what language the user wants, ask the user, as Wikipedia does.
 
T

Tom Cole

In comp.lang.javascript message <d70ff805-94df-4a01-8aeb-5cd0d884acbe@m7
3g2000hsh.googlegroups.com>, Fri, 6 Jun 2008 11:05:21, microgolf


The place where the user is, the place where the user lives, and the
place where the user comes from, and the places where the user's
preferred language originated or is common, are not necessarily the
same.  And the computer is not necessarily set to the local language.

Consider a hypothetical Ambassador to Poland who was born in Korea and
is visiting the residence of the French Ambassador to Bulgaria, and who
wants to read about a baseball game.

To find what language the user wants, ask the user, as Wikipedia does.

--
 (c) John Stockton, nr London, UK. [email protected]  Turnpike v6.05  MIME.
 Web  <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
 Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
 Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

You may also try using something like:

var lang = navigator['language'] || navigator['userLanguage'];

And then use that to help you determine. For example mine returns en-
us (or en-Us or en-US, depending on the browser).

Of course the best way is to ask.
 
V

VK

In comp.lang.javascript message <d70ff805-94df-4a01-8aeb-5cd0d884acbe@m7
3g2000hsh.googlegroups.com>, Fri, 6 Jun 2008 11:05:21, microgolf
<[email protected]> posted:
The place where the user is, the place where the user lives, and the
place where the user comes from, and the places where the user's
preferred language originated or is common, are not necessarily the
same. And the computer is not necessarily set to the local language.
Consider a hypothetical Ambassador to Poland who was born in Korea and
is visiting the residence of the French Ambassador to Bulgaria, and who
wants to read about a baseball game.
To find what language the user wants, ask the user, as Wikipedia does.
--
(c) John Stockton, nr London, UK. [email protected] Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

You may also try using something like:

var lang = navigator['language'] || navigator['userLanguage'];

And then use that to help you determine. For example mine returns en-
us (or en-Us or en-US, depending on the browser).

Of course the best way is to ask.

The best way is to make an educated guess first - but to leave an
option to change if the guess is wrong. As it was pointed out, there
may be tricky occasional situations, say an American contractor in
Germany using office PS with German Windows XP but en-US Firefox or
IE. Or even German OS, German browser but preferred content language
manually set to en-US. Unfortunately navigator.userLanguage (IE) and
especially navigator.language (some others) are currently very lousy
implemented in this aspect. They are still usable for an educated
guess but an option for manual language switch should be provided.

var lang = (navigator.userLanguage || navigator.language ||
defaultLanguage);
 
J

Jorge

There are ways to determine the user's location (with more or less
precision) based on his IP address.

But then, keep in mind that she might be coming trough a proxy.

--Jorge.
 
T

Thomas 'PointedEars' Lahn

Tom said:
microgolf posted:
The place where the user is, the place where the user lives, and the
place where the user comes from, and the places where the user's
preferred language originated or is common, are not necessarily the
same. And the computer is not necessarily set to the local language.

Consider a hypothetical Ambassador to Poland who was born in Korea and
is visiting the residence of the French Ambassador to Bulgaria, and who
wants to read about a baseball game.

To find what language the user wants, ask the user, as Wikipedia does.
[...]
You may also try using something like:

var lang = navigator['language'] || navigator['userLanguage'];

You can use dot notation instead, the property names are identifiers here.
And then use that to help you determine.
Don't.

For example mine returns en-us (or en-Us or en-US, depending on the browser).

My Firefox would yield "en-US" even though neither am I a speaker of English
as first language, nor is the country I live in and I am are currently
located in called The United States of America.
Of course the best way is to ask.

Most definitely. However, the Accept-Language header provides a much better
hint than any `navigator' properties.


PointedEars
 

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
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top