I'm having trouble with the pug templates' localization while using i18n. The language continues reverting to "en," but I've set the locale:'sl' in the send() method, which I got from the email-templates manual.
Here is my code in typescript:
import * as path from 'path';
import Email = require("email-templates");
import { transporter } from '../mailerConnection';
import { I18n } from 'i18n';
export async function sendOutActivationEmail() {
const i18n = new I18n();
i18n.configure({
locales: ['en', 'sl'],
directory: path.join(__dirname, '../../locales'),
register: global
});
const email = new Email({
message: {
from: '"test" <noreplay@test.com>'
},
// uncomment below to send emails in development/test env:
//send: true,
transport: transporter,
i18n: i18n
});
email
.send({
template: path.join(__dirname, '../templates', 'activation'),
message: {
to: 'test@gmail.com'
},
locals: {
locale: 'sl',
name: 'Test'
}
})
.then(console.log)
.catch(console.error);
}
sendOutActivationEmail().catch(console.error);
Here is html.pug template:
p= __('message')
Here is en.json:
{
"message": "message1"
}
Here is sl.json:
{
"message": "messageSLO"
}
Here is the link to email-templates localization documentation: https://www.npmjs.com/package/email-templates#localization
What am I doing wrong that the functions doesn't switch to "sl" language? Thanks.