Javascript I18下一个detectLngFromPath不工作

Javascript I18下一个detectLngFromPath不工作,javascript,i18next,Javascript,I18next,我正在尝试使用express.js在我的项目上设置i18n,现在正在尝试制作工作包,以便myproject.com/en/other/path/显示英语,myproject.com/ee/other/path显示拉脱维亚文本。 但该模块似乎无法从路径中检测语言。起初我认为它可能会在路径中找到语言,但不会自动设置它,但调试req时,i18n会在语言上返回“en”,我做错了什么 以下是与i18n相关的代码: 设置i18next app.js: var i18n = require('i18next'

我正在尝试使用express.js在我的项目上设置i18n,现在正在尝试制作工作包,以便myproject.com/en/other/path/显示英语,myproject.com/ee/other/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;

查看运行示例测试:


->索引从0开始-尝试设置detectLngFromPath=0有点滑稽,但发现问题是使用“ee”来识别爱沙尼亚,而不是“et”,现在一切似乎都正常,但通过测试它帮助找到了问题。