yads / nodemailer-express-handlebars

A plugin for nodemailer that uses express-handlebars view engine to generate emails
87 stars 30 forks source link

How to add internationalization #40

Closed averri closed 4 years ago

averri commented 4 years ago

I would like to know how to add support to internationalization of email templates using the project https://formatjs.io/handlebars/.

This is the basic code used to send emails:

const nodemailer = require('nodemailer')
const hbs = require('nodemailer-express-handlebars')

const transport = nodemailer.createTransport({
  host: 'localhost',
  port: 1025,
  ignoreTLS: true,
  secure: false
})

transport.use('compile', hbs({
  viewEngine: {
    extName: '.hbs',
    partialsDir: 'src/templates',
    layoutsDir: 'src/templates/layouts',
    defaultLayout: 'main.hbs',
  },
  viewPath: 'src/templates',
  extName: '.hbs'
}))

transport.sendMail({
  from: 'alex@email.com',
  to: 'otheruser@email.com',
  subject: 'Confirm Login',
  template: 'confirm-login',
  context: {
    user: 'alex'
  }
})
yads commented 4 years ago

This seems like a question for the formatjs folks. This package just passes through templates to handlebars directly. So the question is how to integrate express-handlebars and formatjs.