admin管理员组文章数量:1026650
I'm using Node.js together with Express framework and i18n module. So I use
var i18n = require('i18n');
app.configure(function() {
[...]
app.use(i18n.init);
app.use(app.router);
});
in my app settings. Everything works fine, but what I really need is to force i18n to use the langauage I want. The scenario is as follows: when user is not logged in, then i18n searches for the langauage in accept-language
header and it is ok. But when user is logged in, then I want to hold chosen langauage somewhere in user settings, retrieve it and force i18n module to use this langauage. How to do this (assuming I already know how to save/retrieve the langauge into/from db)?
I'm using Node.js together with Express framework and i18n module. So I use
var i18n = require('i18n');
app.configure(function() {
[...]
app.use(i18n.init);
app.use(app.router);
});
in my app settings. Everything works fine, but what I really need is to force i18n to use the langauage I want. The scenario is as follows: when user is not logged in, then i18n searches for the langauage in accept-language
header and it is ok. But when user is logged in, then I want to hold chosen langauage somewhere in user settings, retrieve it and force i18n module to use this langauage. How to do this (assuming I already know how to save/retrieve the langauge into/from db)?
- just to mention i18next - i18n for node.js might be a good alternative - just have a look! – jamuhl Commented Sep 7, 2012 at 10:25
2 Answers
Reset to default 12Ach, sorry. I should wait a bit and inspect the i18n module. It seems that module provides to functions
i18n.getLocale();
which retrieves current language and
i18n.setLocale('en');
which sets locale as we want. The documentation really should mention this. It is important, I hope the answer helps someone. :)
This was just released yesterday, but it sounds like it will hit the issue you are running into: locale
I'm using Node.js together with Express framework and i18n module. So I use
var i18n = require('i18n');
app.configure(function() {
[...]
app.use(i18n.init);
app.use(app.router);
});
in my app settings. Everything works fine, but what I really need is to force i18n to use the langauage I want. The scenario is as follows: when user is not logged in, then i18n searches for the langauage in accept-language
header and it is ok. But when user is logged in, then I want to hold chosen langauage somewhere in user settings, retrieve it and force i18n module to use this langauage. How to do this (assuming I already know how to save/retrieve the langauge into/from db)?
I'm using Node.js together with Express framework and i18n module. So I use
var i18n = require('i18n');
app.configure(function() {
[...]
app.use(i18n.init);
app.use(app.router);
});
in my app settings. Everything works fine, but what I really need is to force i18n to use the langauage I want. The scenario is as follows: when user is not logged in, then i18n searches for the langauage in accept-language
header and it is ok. But when user is logged in, then I want to hold chosen langauage somewhere in user settings, retrieve it and force i18n module to use this langauage. How to do this (assuming I already know how to save/retrieve the langauge into/from db)?
- just to mention i18next - i18n for node.js might be a good alternative - just have a look! – jamuhl Commented Sep 7, 2012 at 10:25
2 Answers
Reset to default 12Ach, sorry. I should wait a bit and inspect the i18n module. It seems that module provides to functions
i18n.getLocale();
which retrieves current language and
i18n.setLocale('en');
which sets locale as we want. The documentation really should mention this. It is important, I hope the answer helps someone. :)
This was just released yesterday, but it sounds like it will hit the issue you are running into: locale
本文标签: javascriptinternationalization in NodejsExpressi18nStack Overflow
版权声明:本文标题:javascript - internationalization in Node.js, Express, i18n - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1740007389a1707546.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论