NodeJS email-templates i18n localization

0 votes

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.

Jun 15 in Node-js by Vaani
• 7,020 points
21 views

1 answer to this question.

0 votes
The i18n object does not appear to be documented in email-templates, but you'll probably need to give the required translations someplace...

This, on the other hand, appears to be more promising:

https://dev.to/adrai/how-does-server-side-internationalization-i18n-look-like-5f4c#email
answered Jun 16 by Neha
• 8,560 points

Related Questions In Node-js

0 votes
0 answers

Generate temporary email addresses and read emails - NodeJS

I want to develop a NodeJS application ...READ MORE

1 day ago in Node-js by Vaani
• 7,020 points
2 views
0 votes
1 answer

How do I “include” functions from my other files in nodejs?

Hello @kartik, You require any js file,so you just ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,720 points
1,478 views
0 votes
1 answer

Error: listen EADDRINUSE while using nodejs?

Hello @kartik, EADDRINUSE means that the port number which listen() tries ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,720 points
1,951 views
0 votes
1 answer

Error:npm WARN unmet dependency in nodejs

Hii @kartik, Following are the possible solution : Manually ...READ MORE

answered Jul 12, 2020 in Node-js by Niroj
• 82,720 points
2,633 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
967 views
0 votes
1 answer
0 votes
1 answer

Mixing JavaScript and TypeScript in Node.js

Combine the following TypeScript compiler options --allowJs Explicitly supports ...READ MORE

answered Jun 15 in TypeSript by Nina
• 2,900 points
6 views
0 votes
1 answer

Nodejs instagram-web can't save login session locally

There are several things you can do: Dictionary ...READ MORE

answered May 27 in Node-js by Neha
• 8,560 points
19 views
0 votes
1 answer

NodeJS - Upload ~36MB file to VirusTotal failing

The VirusTotal file/scan API request has a ...READ MORE

answered May 27 in Node-js by Neha
• 8,560 points
24 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP