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

Categories

0 votes
828 views
in Technique[技术] by (71.8m points)

internationalization - i don't know , how to implement i18n in express

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

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

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...