jamuhl/i18next-node — pull request #134 by robrich (2014-04-24 19:31:20+00:00)
Title: Allow userland detectLanguage function and overriding other functions in init()

If I have a locale store that isn't the i18next cookie, it isn't the query string, and it isn't in the url, I have to clone the entire handle function and patch one line in https://github.com/jamuhl/i18next-node/blob/master/lib/i18next.js#L68 to get a request-specific locale. With this patch, I can configure an override detectLanguage fn in #init, and if it isn't found, look in the normal places:
```js
i18n.init({
detectLanguageFn: function (req, res, options) {
// return locale from session (if any), fall back to query, url, and cookie
return req.session.locale;
}
});
```
Or if I want to completely take over detecting the locale, I can also do so:
I can now also hook into logging to direct it elsewhere:
```js
i18n.init({
functions: {
detectLanguage: function (req, res) {
// return locale from session, don't use any other store
return req.session.locale || 'en-US';
}
}
});
```
I can now also hook into logging to direct it elsewhere:
```js
i18n.init({
functions: {
log: winston.info
}
});
```
Tests that prove this behavior are also included.