i am trying to set up i18n on my project (using express.js), right now trying to make work i18next package, so that myproject.com/en/other/path/ shows to english and myproject.com/ee/other/path shows Latvian text. But the module doesn't seem to detect language from path. At first i thought it might find the langauge in the path but doesn't not automaticly set it, but debuging req, i18n returns 'en' on language, what am i doing wrong?
Here is the code of related to i18n:
setting-up 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,
});
later in app.js reference the route file:
i18n.registerAppHelper(app);
app.use(i18n.handle);
var routes = require('./routes/index');
app.use('/', routes);
/routes/index.js file:
var express = require('express');
var router = express.Router();
router.get('/:lang', function(req, res) {
res.render('index', { title: 'Hello' });
});
module.exports = router;
have a look at running sample (test): https://github.com/jamuhl/i18next-node/blob/master/test/i18next.detectLanguage.spec.js#L12
-> index starting from 0 - try setting detectLngFromPath=0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.