Thursday, September 04, 2008

figuring out the user's language preferences, client-side

Your browser sends an HTTP header field called "Accept-Language" (see 14.4) when you make a request to a web server. It tells the server which languages you prefer, and in which ordering, so the server can send you localized content with graceful fallbacks. You can muck with these, for example, in your Firefox settings under Preferences > Content > Languages.

So I'd like to do this on the client side. I had the bright idea that I would just build an XMLHttpRequest object and ask it what headers it was about to send (XHRs do send this field), but GWT's HTTP objects don't let you get at request headers that you haven't explicitly set. The very good reason for this is that XMLHttpRequest objects don't let you query their headers. Oh noes.

It may be that the way to do this is with a bit of server-side cleverness, but that's not the answer I want. Unless somebody happens to have a way to snag these settings from JavaScript...

No comments: