Answer the question
In order to leave comments, you need to log in
What does req.setLocale is not a function error mean?
I'm trying to make multilanguage on i18n
I get an error if I switch to domains.dev/en or ru
error
TypeError: req.setLocale is not a function
at init (B:/OSPanel/domains/domains.dev/frontend/server/locales/services/i18n_urls.js:24:13)
services.i18nUrls.configure(app, i18n, {
locales: ['ru', 'en'],
defaultLocale: 'ru',
cookie: process.env.npm_package_name + '_i18n_cookie',
indent: ' '
});
module.exports = {
configure: function(app, i18n, config) {
app.locals.i18n = config;
i18n.configure(config);
},
init: function(req, res, next) {
var rxLocale = /^\/(\w\w)/i;
if (rxLocale.test(req.url)){
var locale = rxLocale.exec(req.url)[1];
if (req.app.locals.i18n.locales.indexOf(locale) >= 0)
req.setLocale(locale);
}
//else // no need to set the already default
next();
},
url: function(app, url) {
var locales = app.locals.i18n.locales;
var urls = [];
for (var i = 0; i < locales.length; i++)
urls[i] = '/' + locales[i] + url;
urls[i] = url;
return urls;
}
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question