sails: `defaultLocale` option in `i18n.js` is not working , always use the `en` locale

I try to set defaultLocale as other languages, say defaultLocale: 'de', but it is not working, unless I set the locale specially in controller as res.setLocale('de'), it will use the right locale.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

I temporarily solve this by add res.setLocale(sails.config.i18n.defaultLocale); to i18n hook, as below:

routes: {

      before: {

        '/*': function (req, res, next) {

          i18n.init(req, res, function() {
            res.locals.i18n = res.i18n = res.__;
            res.setLocale(sails.config.i18n.defaultLocale);
            next();
          });

        }
      }
    },

Any better solution to this?