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

@@ -169,6 +169,7 @@ module.exports.CreateMeshSMS = function (parent) {
function getTemplate(templateNumber, domain, 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 (lang != null) { lang = lang.split('-')[0]; } // Take the first part of the language, "xx-xx"
var r = {}, emailsPath = null;
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
if (txtfile == null) { return null; }