我正在尝试在我的项目上设置i18n (使用express.js),现在正在尝试制作work i18next包,以便myproject.com/en/other/path/向英语显示,myproject.com/ee/其他/path显示拉脱维亚文本。但是这个模块似乎没有从路径中检测到语言。一开始,我想它可能会在路径中找到语言,但没有自动设置它,但是在调试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;发布于 2014-04-24 06:49:33
查看运行示例(测试):https://github.com/jamuhl/i18next-node/blob/master/test/i18next.detectLanguage.spec.js#L12
从0开始的->索引-尝试设置detectLngFromPath=0
https://stackoverflow.com/questions/23244085
复制相似问题