#1862 WebReq Locale Proposal

andy Mon 26 Mar 2012

Proposal for a few small changes to simplify how we handle localization for web requests.

WebReq

Lets add a new method to WebReq to return a Locale based on the HTTP Accept-Language header:

class WebReq
{
  ** The Locale for this request, based on 'headers["Accept-Language"]'. If
  ** a Locale cannot be determined, or header is missing, return Locale.cur.
  virtual Locale locale()
}

I think we do that no matter what, since its boilerplate code.

Wisp

The easiest way to build localization support is to simply change Locale.cur. This way you never have to worry about forgetting to set or pass your WebReq.locale. So the second part of this proposal is to change Wisp to always set Locale.cur based on WebReq.locale for each web request.

Any objections? Is everyone ok with Wisp always setting Locale.cur? That seems the really common use case.

dobesv Tue 27 Mar 2012

Makes sense to me! I like the way you've made locale thread-local, I was always perplexed about how to tackle this issue in Java where Locale is global and so per-request locale was a pain in the butt.

andy Fri 11 May 2012

Ok pushed this change. I made one tweak. WebReq.locales returns the list of accepted locales instead of just the best match.

See changeset and changeset for details.

Login or Signup to reply.