我使用express和i18next-node。当我尝试更改我的路线内的语言时,我有一个问题。如果我把它放到url上也没问题。我的init:
i18n.init({
saveMissing: true,
sendMissingTo : 'all',
fallbackLng : 'it-IT',
ignoreRoutes: ['img/', 'public/', 'css/', 'js/'],
useCookie: true,
debug: true
});在我的路线上(我看到了u18next node setLng seems that doesn´t work)我有
var theLang = 'fr-FR';
console.log(req.i18n.lng()); // this gives me it-IT
req.i18n.setLng(theLang); // I thouth this would change the lang to fr-FR
console.log('now I have ' +theLang+ ' '+ i18n.lng());结果是fr-FR it-IT
为什么?我怎样才能改变它?我还没有会话,这是用户得到的第一个页面,取决于url (没有lang),我选择了语言。我该怎么做?谢谢
发布于 2015-06-29 19:56:58
setLng有回调,请尝试:
req.i18n.setLng(theLang, function(){
console.log('now I have ' +theLang+ ' '+ i18n.lng());
});https://stackoverflow.com/questions/30153455
复制相似问题