You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This looks like a great i18n lib. I have some issues regarding a nodejs script. I need to parse a ejs template and I am trying to integrate this lib into the project.
This is how my code looks like.
var path = require('path');
var ejs = require('ejs');
var i18next = require("i18next");
var Backend = require("i18next-node-fs-backend");
var i18nextOptions = {
debug: true,
load: ['en'],
preload: ['en'],
fallbackLng: 'en',
backend: {
loadPath: path.join(__dirname,'/locales/{{lng}}/{{ns}}.json'),
addPath: path.join(__dirname,'/locales/{{lng}}/{{ns}}.missing.json')
},
getAsync:false,
postProcess: true,
saveMissing: true,
saveMissingTo: path.join(__dirname,'/locales/en/missing.json')
}
i18next.use(Backend).init(i18nextOptions, function (err, result) {
return result
})
var t = function(key, count) {
if(count) {
return i18next.t(key, {count: count})
}
return i18next.t(key);
};
var tpl = ejs.renderFile(path.join(__dirname, '/views/index.ejs'), {t:t, title: 'Title', message: 'This is a message'})
console.log(tpl)
Instead of getting the translations, I get only the keys. I have tried to do this: console.log(i18next.t('key'))
but with no success. It still prints the key and not the value.
this is the output:
'<!DOCTYPE html>
<html>
<head>
<title>test ejs with i18next </title>
</head>
<body>
<div id="greeting">
Title This is a message hello You_message
</div>
</body>
</html>'
where hello is a key name and You_message is also a key name.
Any suggestions? Thanks in advance.
Best,
cojok
PS: I forgot to put in the output of the debugger:
Checked with lng: 'en' and it gives back the same error.
I am not using expressjs at all. This nodejs script will be part of a lambda function. I will have a look on the i18next-express-middleware language detector.
Funny is that my code works inside an expressjs app.
Hi there,
This looks like a great i18n lib. I have some issues regarding a nodejs script. I need to parse a ejs template and I am trying to integrate this lib into the project.
This is how my code looks like.
Instead of getting the translations, I get only the keys. I have tried to do this:
console.log(i18next.t('key'))
but with no success. It still prints the key and not the value.
this is the output:
where hello is a key name and You_message is also a key name.
Any suggestions? Thanks in advance.
Best,
cojok
PS: I forgot to put in the output of the debugger:
The text was updated successfully, but these errors were encountered: