sails-hook-validation icon indicating copy to clipboard operation
sails-hook-validation copied to clipboard

Think about alternative to sails.config.i18n.requestLocale

Open rishabhmhjn opened this issue 9 years ago • 4 comments

Using sails.config.i18n.requestLocale = request.getLocale(); is a bad idea!

It assumes that all the requests are processed serially and so, parallel requests will fail to get the correct locale!

https://github.com/lykmapipo/sails-hook-validation/blob/master/index.js#L73

    return {
        //intercent all request and current grab request locale
        routes: {
            before: {
                'all /*': function grabLocale(request, response, next) {
                    //configure i18n current request locale
                    sails.config.i18n.requestLocale = request.getLocale();

                    //continue
                    next();
                }
            }
        },

...

rishabhmhjn avatar Jan 04 '16 15:01 rishabhmhjn

@rishabhmhjn

May you please add a spec/scenario that fail the current implementation. As far as sails hook implementation is concern and regardless of the number request all request will be processed to obtain their locale.

Is it bad idea is attaching locale to a request object?. If so am open for the correct implementation.

lykmapipo avatar Jan 04 '16 16:01 lykmapipo

Got that. Please give me sometime to create an appropriate test for it. Will update you over here

rishabhmhjn avatar Jan 04 '16 17:01 rishabhmhjn

@rishabhmhjn

Thanks.

lykmapipo avatar Jan 04 '16 17:01 lykmapipo

@rishabhmhjn I don't see how you proposition fixes anything. You set a property on a global. The before hook can be called numerous times before you access the requestLocale in the validateCustom function anyway.

I can't think of a way of fixing the problem without a reference to the request in the validateCustom function.

armellarcier avatar Jul 28 '17 11:07 armellarcier