那麼我創建了一個簡單的項目來測試它(代碼snnipets波紋管),因爲我在主項目中有完全相同的問題,所以我想也許其他組件之一可能會導致此問題,但是我在孤立的項目中遇到了同樣的問題,現在我不知道如何使它工作。 初始化的配置是這樣的:i18next在ejs上不能正常工作
i18n.init({
ns: {
namespaces: ['ns.common', 'ns.special'],
defaultNs: 'ns.special'
},
resSetPath: 'locales/__lng__/new.__ns__.json',
saveMissing: true,
debug: true,
sendMissingTo: 'fallback',
preload: ['en', 'de'],
detectLngFromPath: 0,
ignoreRoutes: ['img/', 'img', 'img/', '/img/', 'css/', 'i18next/']
});
// Configuration
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(i18n.handle); // have i18n befor app.router
app.set('view engine', 'ejs');
app.set('views', __dirname);
i18n.registerAppHelper(app)
.serveClientScript(app)
.serveDynamicResources(app)
.serveMissingKeyRoute(app);
i18n.serveWebTranslate(app, {
i18nextWTOptions: {
languages: ['de-DE', 'en-US', 'dev'],
namespaces: ['ns.common', 'ns.special'],
resGetPath: "locales/resources.json?lng=__lng__&ns=__ns__",
resChangePath: 'locales/change/__lng__/__ns__',
resRemovePath: 'locales/remove/__lng__/__ns__',
fallbackLng: "dev",
dynamicLoad: true
}
});
的EJS是這樣的: html <body> <span>Should show a hello world</span></br> <span>;<%t('hello.world')%></span> </body>
和我添加這樣的t的函數(修正噸不定義的錯誤):
app.locals.t = function(key){
return i18n.t(key);
};
一切應顯示網站上的下一個視圖:
https://cloud.githubusercontent.com/assets/2654171/7738735/bef1a7ce-ff25-11e4-89f8-257502b27396.PNG
但不是,它只是表明這一點:
https://cloud.githubusercontent.com/assets/2654171/7738741/d0685f84-ff25-11e4-9c3d-1a39ca7c1bb1.PNG
我真的很感激一些建議或使用國際化EJS的例子。 通過我使用的方法: -Express 4 -ejs 1 -i18next 1.7.10