i18下一个detectLngFromPath不工作
i18next detectLngFromPath not working
我正试图在我的项目上设置i18n(使用express.js),现在正试图使工作成为i18next包,以便myproject.com/en/other/path/显示为英语,myproject.com/ee/other/path显示拉脱维亚文本。但该模块似乎并没有从路径中检测到语言。起初,我认为它可能会在路径中找到langauge,但不会自动设置它,但在调试req时,i18n在语言上返回'en',我做错了什么?
这是与i18n相关的代码:
设置i18next app.js:
var i18n = require('i18next');
i18n.init({
ignoreRoutes: ['images/', 'public/', 'css/', 'js/'],
supportedLngs: ['en', 'ee'],
fallbackLng: 'en',
//detectLngQS: 'lang', // ?lang=ee
detectLngFromPath: 1,
forceDetectLngFromPath: true,
detectLngFromHeaders: false,
useCookie: false,
//cookieName: 'interspace-lang-cookie', // default 'i18next'
debug: true,
});
稍后在app.js中引用路由文件:
i18n.registerAppHelper(app);
app.use(i18n.handle);
var routes = require('./routes/index');
app.use('/', routes);
/routes/index.js文件:
var express = require('express');
var router = express.Router();
router.get('/:lang', function(req, res) {
res.render('index', { title: 'Hello' });
});
module.exports = router;
查看运行示例(测试):https://github.com/jamuhl/i18next-node/blob/master/test/i18next.detectLanguage.spec.js#L12
->索引从0开始-尝试设置detectLngFromPath=0
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- jQuery UI自动完成突然停止工作
- AngularJS UI路由器不能像ng路由器那样工作
- HTML5音频加载和播放获胜'我不能在iPad上工作
- JavaScript打印功能使日历停止工作
- Javascript.getHours()工作不正常
- 为什么这在IE中的工作方式与在Firefox中不同
- 视频HTML没有'无法在Internet Explorer 11上工作
- 扩展移相器按钮类不工作
- Firebase迁移-简单的Firebase.set没有'不再工作了——旧的还是新的
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- 正在尝试使用if和else添加类,但无法正常工作
- Jquery FadeIn FadeOut 只工作一次
- Foreach无法在Typescript中工作
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- JS可以在Chrome中工作,但不能在Firefox中工作
- ajaxToolkit PopupControlExtender不工作.过时的
- HTML标记在脚本标记中工作
- javascript扫雷器floodfill算法不能正常工作