Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
835 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...