Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i try to implement 'i18n' in express.

but i can't go forward now...

i tried like this.

index.js

const app = express()
(...code)
var i18n = require('./i18n');
app.use(i18n);
(...code)

i18n.js

var i18n = require('i18n'); 

i18n.configure({
  locales:['en', 'fr'], 
  directory: __dirname + '/locales', 
  defaultLocale: 'en', 
  cookie: 'lang', 
});

module.exports = function(req, res, next) {
  i18n.init(req, res);
  res.locals.__ = res.__;
  var current_locale = i18n.getLocale();
  return next();
};

then when i try to start the express server, it made locales folder and en.json and fr.json file.

but i don't know what should i do after this. and even i can't understand this part of i18n.js

module.exports = function(req, res, next) {
  i18n.init(req, res);
  res.locals.__ = res.__;
  var current_locale = i18n.getLocale();
  return next();
};

would you give me hint to solve this issue ?

question from:https://stackoverflow.com/questions/65857669/i-dont-know-how-to-implement-i18n-in-express

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
678 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...