fix email/sms/messaging customised templates #6994

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
si458 2025-05-24 12:47:28 +01:00
parent 1399ce3590
commit 5fcffcd608
3 changed files with 59 additions and 2 deletions

View File

@ -116,6 +116,27 @@ module.exports.CreateMeshMail = function (parent, domain) {
} }
} }
// If no email template found, use the default translated email template
if (((htmlfile == null) || (txtfile == null)) && (lang != null) && (lang != 'en')) {
var translationsPath = obj.parent.path.join(obj.parent.webEmailsPath, 'translations');
var translationsPathHtml = obj.parent.path.join(obj.parent.webEmailsPath, 'translations', name + '_' + lang + '.html');
var translationsPathTxt = obj.parent.path.join(obj.parent.webEmailsPath, 'translations', name + '_' + lang + '.txt');
if (obj.parent.fs.existsSync(translationsPath) && obj.parent.fs.existsSync(translationsPathHtml) && obj.parent.fs.existsSync(translationsPathTxt)) {
htmlfile = obj.parent.fs.readFileSync(translationsPathHtml).toString();
txtfile = obj.parent.fs.readFileSync(translationsPathTxt).toString();
}
}
// If no translated email template found, use the default email template
if ((htmlfile == null) || (txtfile == null)) {
var pathHtml = obj.parent.path.join(obj.parent.webEmailsPath, name + '.html');
var pathTxt = obj.parent.path.join(obj.parent.webEmailsPath, name + '.txt');
if (obj.parent.fs.existsSync(pathHtml) && obj.parent.fs.existsSync(pathTxt)) {
htmlfile = obj.parent.fs.readFileSync(pathHtml).toString();
txtfile = obj.parent.fs.readFileSync(pathTxt).toString();
}
}
// No email templates // No email templates
if ((htmlfile == null) || (txtfile == null)) { return null; } if ((htmlfile == null) || (txtfile == null)) { return null; }

View File

@ -397,6 +397,7 @@ module.exports.CreateServer = function (parent) {
function getTemplate(templateNumber, domain, lang) { function getTemplate(templateNumber, domain, lang) {
parent.debug('email', 'Getting SMS template #' + templateNumber + ', lang: ' + lang); parent.debug('email', 'Getting SMS template #' + templateNumber + ', lang: ' + lang);
if (Array.isArray(lang)) { lang = lang[0]; } // TODO: For now, we only use the first language given. if (Array.isArray(lang)) { lang = lang[0]; } // TODO: For now, we only use the first language given.
if (lang != null) { lang = lang.split('-')[0]; } // Take the first part of the language, "xx-xx"
var r = {}, emailsPath = null; var r = {}, emailsPath = null;
if ((domain != null) && (domain.webemailspath != null)) { emailsPath = domain.webemailspath; } if ((domain != null) && (domain.webemailspath != null)) { emailsPath = domain.webemailspath; }
@ -404,7 +405,7 @@ module.exports.CreateServer = function (parent) {
else if (obj.parent.webEmailsPath != null) { emailsPath = obj.parent.webEmailsPath; } else if (obj.parent.webEmailsPath != null) { emailsPath = obj.parent.webEmailsPath; }
if ((emailsPath == null) || (obj.parent.fs.existsSync(emailsPath) == false)) { return null } if ((emailsPath == null) || (obj.parent.fs.existsSync(emailsPath) == false)) { return null }
// Get the non-english email if needed // Get the non-english sms if needed
var txtfile = null; var txtfile = null;
if ((lang != null) && (lang != 'en')) { if ((lang != null) && (lang != 'en')) {
var translationsPath = obj.parent.path.join(emailsPath, 'translations'); var translationsPath = obj.parent.path.join(emailsPath, 'translations');
@ -414,7 +415,7 @@ module.exports.CreateServer = function (parent) {
} }
} }
// Get the english email // Get the english sms
if (txtfile == null) { if (txtfile == null) {
var pathTxt = obj.parent.path.join(emailsPath, 'sms-messages.txt'); var pathTxt = obj.parent.path.join(emailsPath, 'sms-messages.txt');
if (obj.parent.fs.existsSync(pathTxt)) { if (obj.parent.fs.existsSync(pathTxt)) {
@ -422,6 +423,23 @@ module.exports.CreateServer = function (parent) {
} }
} }
// If no english sms and a non-english language is requested, try to get the default translated sms
if (txtfile == null && (lang != null) && (lang != 'en')) {
var translationsPath = obj.parent.path.join(obj.parent.webEmailsPath, 'translations');
var translationsPathTxt = obj.parent.path.join(obj.parent.webEmailsPath, 'translations', 'sms-messages_' + lang + '.txt');
if (obj.parent.fs.existsSync(translationsPath) && obj.parent.fs.existsSync(translationsPathTxt)) {
txtfile = obj.parent.fs.readFileSync(translationsPathTxt).toString();
}
}
// If no default translated sms, try to get the default english sms
if (txtfile == null) {
var pathTxt = obj.parent.path.join(obj.parent.webEmailsPath, 'sms-messages.txt');
if (obj.parent.fs.existsSync(pathTxt)) {
txtfile = obj.parent.fs.readFileSync(pathTxt).toString();
}
}
// No email templates // No email templates
if (txtfile == null) { return null; } if (txtfile == null) { return null; }

View File

@ -169,6 +169,7 @@ module.exports.CreateMeshSMS = function (parent) {
function getTemplate(templateNumber, domain, lang) { function getTemplate(templateNumber, domain, lang) {
parent.debug('email', 'Getting SMS template #' + templateNumber + ', lang: ' + lang); parent.debug('email', 'Getting SMS template #' + templateNumber + ', lang: ' + lang);
if (Array.isArray(lang)) { lang = lang[0]; } // TODO: For now, we only use the first language given. if (Array.isArray(lang)) { lang = lang[0]; } // TODO: For now, we only use the first language given.
if (lang != null) { lang = lang.split('-')[0]; } // Take the first part of the language, "xx-xx"
var r = {}, emailsPath = null; var r = {}, emailsPath = null;
if ((domain != null) && (domain.webemailspath != null)) { emailsPath = domain.webemailspath; } if ((domain != null) && (domain.webemailspath != null)) { emailsPath = domain.webemailspath; }
@ -194,6 +195,23 @@ module.exports.CreateMeshSMS = function (parent) {
} }
} }
// If no english sms and a non-english language is requested, try to get the default translated sms
if (txtfile == null && (lang != null) && (lang != 'en')) {
var translationsPath = obj.parent.path.join(obj.parent.webEmailsPath, 'translations');
var translationsPathTxt = obj.parent.path.join(obj.parent.webEmailsPath, 'translations', 'sms-messages_' + lang + '.txt');
if (obj.parent.fs.existsSync(translationsPath) && obj.parent.fs.existsSync(translationsPathTxt)) {
txtfile = obj.parent.fs.readFileSync(translationsPathTxt).toString();
}
}
// If no default translated sms, try to get the default english sms
if (txtfile == null) {
var pathTxt = obj.parent.path.join(obj.parent.webEmailsPath, 'sms-messages.txt');
if (obj.parent.fs.existsSync(pathTxt)) {
txtfile = obj.parent.fs.readFileSync(pathTxt).toString();
}
}
// No email templates // No email templates
if (txtfile == null) { return null; } if (txtfile == null) { return null; }