forwardemail / email-templates

Create, preview (browser/iOS Simulator), and send custom email templates for Node.js. Made for @forwardemail, @ladjs, @cabinjs, @spamscanner, and @breejs.
https://forwardemail.net/docs/send-emails-with-node-js-javascript
MIT License
3.66k stars 339 forks source link

i18n error: t is not a function #379

Closed mariusoprea03 closed 4 years ago

mariusoprea03 commented 4 years ago

Hi,

I am trying to use the email-templates plugin with the localization but I got the following message: subject.pug:1 > 1| p= ${t('Hi')} ${name}, ${t('welcome')} t is not a function

I am sending this mail from a cloud function and the configuration is like this:

 const i18n = {
        directory: 'pathToLocale',
        defaultLocale: 'ro',
        locales: ['ro', 'en'],
    }
    // Create a new email
    const email = new Email({
        message: {
            from: 'fromAddress'
        },
        transport: transporter,
        il8n: i18n
    });

    from(email
        .send({
            template: 'pathToTemplate',
            message: {
                to: to
            },
            locals: {
                locale: 'ro', // used by il8n
                name: 'Somename'
            }
        })
    ).subscribe(() => {
        response.send("The email was send successfully");
    },
        e => {
            response.status(500).send("An error was occurred when sending the email: " + e);
        });

The template: subject.pug

p= `${t('Hi')} ${name}, ${t('welcome')}`

html.pug

p= `${t('Hi')} ${name},`
p= t('welcomeBody')

ro.json

{
    "Hi": "Buna ziua",
    "welcome": "Bine ai venit",
    "welcomeBody": "Continut bine ai venit"
}

Any idea why I am getting this error? Thanks

niftylettuce commented 4 years ago

I have not been able to reproduce. If you can make a GitHub repository that demonstrates this fails let me know. Or if you can provide more code/snippets/gists that reproduce in a new folder the issue.

Are you on the latest version of email-templates?