Implemented mail translations. Updated debug output from translation.js

This commit is contained in:
Glenn de Haan
2024-10-09 12:39:44 +02:00
parent 1b1a934f87
commit 467ce7edb1
3 changed files with 26 additions and 19 deletions

View File

@@ -10,6 +10,7 @@ const nodemailer = require('nodemailer');
*/
const variables = require('./variables');
const log = require('./log');
const translation = require('./translation');
const qr = require('./qr');
/**
@@ -47,12 +48,17 @@ module.exports = {
*/
send: (to, voucher) => {
return new Promise(async (resolve, reject) => {
// Create new translator
const t = translation('en', 'email');
// Attempt to send mail via SMTP transport
const result = await transport.sendMail({
from: variables.smtpFrom,
to: to,
subject: 'WiFi Voucher Code',
text: `Hi there,\n\nSomeone generated a WiFi Voucher, please use this code when connecting:\n\n${voucher.code.slice(0, 5)}-${voucher.code.slice(5)}`,
subject: t('title'),
text: `${t('greeting')},\n\n${t('intro')}:\n\n${voucher.code.slice(0, 5)}-${voucher.code.slice(5)}`,
html: ejs.render(fs.readFileSync(`${__dirname}/../template/email/voucher.ejs`, 'utf-8'), {
t,
voucher,
unifiSsid: variables.unifiSsid,
unifiSsidPassword: variables.unifiSsidPassword,
@@ -66,6 +72,7 @@ module.exports = {
reject(`[Mail] ${e.message}`);
});
// Check if the email was sent successfully
if(result) {
log.info(`[Mail] Sent to: ${to}`);
resolve(true);

View File

@@ -38,6 +38,6 @@ module.exports = (language = 'en', module) => {
}
// Check if debugging is enabled. If enabled only return key
return variables.translationDebug ? key : translations[key];
return variables.translationDebug ? `%${key}%` : translations[key];
};
};