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, 2022 in Node-js by Vaani
• 7,070 points
1,836 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, 2022 by Neha
• 9,020 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

Jun 27, 2022 in Node-js by Vaani
• 7,070 points
1,084 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,840 points
3,445 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,840 points
6,603 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,840 points
6,330 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
1,942 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,468 views
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, 2022 in TypeSript by Nina
• 3,060 points
783 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, 2022 in Node-js by Neha
• 9,020 points
1,069 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, 2022 in Node-js by Neha
• 9,020 points
901 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP