Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Think about alternative to sails.config.i18n.requestLocale #34

Open
rishabhmhjn opened this issue Jan 4, 2016 · 4 comments · May be fixed by #57
Open

Think about alternative to sails.config.i18n.requestLocale #34

rishabhmhjn opened this issue Jan 4, 2016 · 4 comments · May be fixed by #57

Comments

@rishabhmhjn
Copy link
Contributor

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();
                }
            }
        },

...
@lykmapipo
Copy link
Owner

@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.

@rishabhmhjn
Copy link
Contributor Author

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

@lykmapipo
Copy link
Owner

@rishabhmhjn

Thanks.

@rishabhmhjn rishabhmhjn changed the title Thing about alternative to sails.config.i18n.requestLocale Think about alternative to sails.config.i18n.requestLocale Jan 30, 2016
@armellarcier
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants