Edit Page

req.setLocale()

Override the inferred locale for this request.

Normally, the locale is determined on a per-request basis based on incoming request headers (i.e. a user's browser or device language settings). This command overrides that setting for a particular request.

Usage

#
req.setLocale(override);

Example

#

To allow users to specify their own language settings:

if (this.req.me.preferredLocale) {
  this.req.setLocale(this.req.me.preferredLocale);
}
return exits.success();

Or, if you are not using the "Web app" template and/or actions2:

var me = await User.findOne({ id: req.session.userId });
if (me.preferredLocale) {
  req.setLocale(me.preferredLocale);
}
return res.view('pages/homepage');

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

Reference