Internationalization in Node.js, Express, i18n

I am using Node.js along with the Express platform and the i18n module . Therefore i use

var i18n = require('i18n'); app.configure(function() { [...] app.use(i18n.init); app.use(app.router); }); 

in the settings of my application. Everything works fine, but I really need to get i18n to use the langauage that I want. The scenario is as follows: when the user is not logged in, i18n looks for langauage in the accept-language header, and this is normal. But when the user is logged in, I want to navigate the selected langauage somewhere in the user settings, extract it and force the i18n module to use this langauage. How to do this (if I already know how to save / retrieve langauge to / from db)?

+6
source share
2 answers

Ah, sorry. I have to wait a bit and check the i18n module. The module seems to provide functions

 i18n.getLocale(); 

which extracts the current language and

 i18n.setLocale('en'); 

which sets the locale as we want. The documentation really should mention this. This is important, I hope the answer helps someone. :)

+11
source

It was just released yesterday, but it looks like it will run into the problem you are facing: locale

0
source

Source: https://habr.com/ru/post/906057/


All Articles