Throughout my app I use i18n
without problem. However, for email send through a cron job, I get the error:
ReferenceError: __ is not defined
In app.js
I configure i18n:
const i18n = require("i18n");
i18n.configure({
locales: ["en"],
register: global,
directory: path.join(__dirname, "locales"),
defaultLocale: "en",
objectNotation: true,
updateFiles: false,
});
app.use(i18n.init);
Throughout my app I use it as __('authentication.flashes.not-logged-in')
, like I said without problems. In a mail controller, that is called upon by a cron job, I use it in the same way: __('mailers.buttons.upgrade-now')
. However there, and only there, it produces the mentioned error.
Just to try, I've changed this in the mail controller to i18n.__('authentication.flashes.not-logged-in')
. But then I get another error:
(node:11058) UnhandledPromiseRejectionWarning: TypeError: logWarnFn is not a function
at logWarn (/data/web/my_app/node_modules/i18n/i18n.js:1180:5)
Any idea how to make the emails work that are sent through a cron job?