mashpie/i18n-node — pull request #30 by dlongley (2012-08-07 16:59:00+00:00)
Title: Do not set default locale when a request is given as an argument

The current setLocale() call will set the "defaultLocale" variable even when a request is given as an argument; I believe this is a bug.

If "defaultLocale" is set when a request is given (the 2-argument form of setLocale), then there is an unfortunate side-effect where each subsequent request is treated as if it used the language from the previous one. For example, if the default locale is configured as "de" and a request with "Accept-Language: en" is sent to the server, then any subsequent request from any client that does not have an "Accept-Language" header will be assigned the language "en" instead of "de". Any request that sends an "Accept-Language" header will change the default locale from what was originally configured.

When a request is given as an argument to setLocale, only the locale on the request should be set. Only if no request is given should setLocale modify "defaultLocale".

This pull request also adds a couple of tests to ensure passing a request does not modify the default locale.