首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >i18next detectLngFromPath不工作

i18next detectLngFromPath不工作
EN

Stack Overflow用户
提问于 2014-04-23 12:20:02
回答 1查看 451关注 0票数 0

我正在尝试在我的项目上设置i18n (使用express.js),现在正在尝试制作work i18next包,以便myproject.com/en/other/path/向英语显示,myproject.com/ee/其他/path显示拉脱维亚文本。但是这个模块似乎没有从路径中检测到语言。一开始,我想它可能会在路径中找到语言,但没有自动设置它,但是在调试req时,i18n在语言上返回'en‘,我做错了什么?

这里是与i18n:相关的代码

设置i18next app.js:

代码语言:javascript
复制
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中引用路由文件:

代码语言:javascript
复制
i18n.registerAppHelper(app);
app.use(i18n.handle);

var routes = require('./routes/index');
app.use('/', routes);

/routes/index.js文件:

代码语言:javascript
复制
var express = require('express');
var router = express.Router();

router.get('/:lang', function(req, res) {
  res.render('index', { title: 'Hello' });
});

module.exports = router;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-24 06:49:33

查看运行示例(测试):https://github.com/jamuhl/i18next-node/blob/master/test/i18next.detectLanguage.spec.js#L12

从0开始的->索引-尝试设置detectLngFromPath=0

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23244085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档