Reputation: 33
Well i created an isolated an simple project to test it (code snnipets bellow) because i was having exactly the same problem in the main project so i thought maybe one of the other components could cause this problem, but i had the same problem in the isolated project and now i don't know how to make it work. The initialization an the configuration are like this:
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
}
});
the ejs is like this:
html
<body>
<span>Should show a hello world</span></br>
<span>;<%t('hello.world')%></span>
</body>
and i added the t function like this (correcting the t not defined error):
app.locals.t = function(key){
return i18n.t(key);
};
everything should show the next view on the website:
https://cloud.githubusercontent.com/assets/2654171/7738735/bef1a7ce-ff25-11e4-89f8-257502b27396.PNG
but instead of that it just shows this:
https://cloud.githubusercontent.com/assets/2654171/7738741/d0685f84-ff25-11e4-9c3d-1a39ca7c1bb1.PNG
I would really appreciate some advises or an example of ejs using the i18n. By the way i'm using: -express 4 -ejs 1 -i18next 1.7.10
Upvotes: 0
Views: 1447
Reputation: 33
in order to solve this problem you have to put the code like this:
<span>;<%=t('hello.world')%></span>
Upvotes: 1