在我的整个应用程序中,我使用i18n没有问题。但是,对于通过 cron 作业发送的电子邮件,我收到错误消息:
ReferenceError: __ 未定义
在app.js我配置 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);
在我的应用程序中,我将其用作__('authentication.flashes.not-logged-in'),就像我说的没有问题。在由 cron 作业调用的邮件控制器中,我以相同的方式使用它:__('mailers.buttons.upgrade-now'). 然而,只有在那里,它才会产生上述错误。
只是为了尝试,我已经在邮件控制器中将其更改为i18n.__('authentication.flashes.not-logged-in'). 但后来我得到另一个错误:
(node:11058) UnhandledPromiseRejectionWarning: TypeError: logWarnFn is not a function
at logWarn (/data/web/my_app/node_modules/i18n/i18n.js:1180:5)
知道如何使通过 cron 作业发送的电子邮件正常工作吗?