i18next.js不在子页面上提供

时间:2015-10-14 22:37:27

标签: javascript node.js i18next

我正在用i18next编写节点服务器。

在我的主页(http://localhost:3000)上,i18next.js按预期投放。

在子页面(http://localhost:3000/users/hans)上,但它没有。

(404) GET http://localhost:3000/users/i18next/i18next.js 
frontend.js:3 Uncaught TypeError: Cannot read property 'init' of undefined

我不明白为什么。

app.js

//[...]
var app = express();


var user = require('./routes/users');  // USER ROUTE
var routes = require('./routes/index');

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

i18n.serveClientScript(app).serveDynamicResources(app);
//[...]

frontend.js:

$(document).ready(function() {

    $.i18n.init({
        debug: true,
        detectLngQS: 'lang',
        fallbackLng: 'en',
        load: 'unspecific',
        lowerCaseLng: true,
        resGetPath: './locales/__lng__-__ns__.json',
    }, function() {
        $.t('markup.login');
        $('p, a, h1, label, button').i18n();
    });
    $('.langButton').on('click', function(event) {
        var setLangTo = $(event.target).attr('name');
        console.log(setLangTo);
        $.i18n.setLng(setLangTo, function() {
            $('p, a, h1, label, button').i18n();
        })
    })
});

根据我的理解,i18next.js应该自动提供给任何请求,独立于路由。我也不知道如何改变/的路径,以便js可以正常加载......

我错过了什么吗?错误的顺序(我尝试重新排序无济于事)?我应该更改的任何设置?

感谢您的帮助:)

其他信息

我刚注意到这只发生在用户页面上(两个子级别) 一个子级别(例如localhost:3000 / training)有效.....这很奇怪。 任何想法?

1 个答案:

答案 0 :(得分:0)

我现在感到惭愧......

对于像我这样愚蠢的人:

必须是

script(src='/i18next/i18next.js', type='text/javascript')

而不是

script(src='i18next/i18next.js', type='text/javascript')