Email translations

This commit is contained in:
vjrj 2018-01-22 13:27:46 +01:00
parent 952431d296
commit 6c8fa91f64
30 changed files with 1844 additions and 107 deletions

View file

@ -1,10 +1,12 @@
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import i18n from 'i18next';
import { getFileNameOfLang } from '/imports/api/Utility/server/files.js';
import getPrivateFile from '../../../modules/server/get-private-file';
import templateToHTML from '../../../modules/server/handlebars-email-to-html';
import templateToText from '../../../modules/server/handlebars-email-to-text';
const name = '¡Tod@s contra el Fuego!';
const name = i18n.t('AppName');
const email = '<noreply@comunes.org>';
const from = `${name} ${email}`;
const emailTemplates = Accounts.emailTemplates;
@ -17,7 +19,7 @@ emailTemplates.verifyEmail = {
return `[${name}] Verify Your Email Address`;
},
html(user, url) {
return templateToHTML(getPrivateFile('email-templates/verify-email.html'), {
return templateToHTML(getPrivateFile(getFileNameOfLang('email-templates', 'verify-email', 'html', user.lang)), {
applicationName: name,
firstName: user.profile.name.first,
verifyUrl: url.replace('#/', '')
@ -26,12 +28,12 @@ emailTemplates.verifyEmail = {
text(user, url) {
const urlWithoutHash = url.replace('#/', '');
if (Meteor.isDevelopment) console.info(`Verify Email Link: ${urlWithoutHash}`); // eslint-disable-line
return templateToText(getPrivateFile('email-templates/verify-email.txt'), {
return templateToText(getPrivateFile(getFileNameOfLang('email-templates', 'verify-email', 'txt', user.lang)), {
applicationName: name,
firstName: user.profile.name.first,
verifyUrl: urlWithoutHash,
verifyUrl: urlWithoutHash
});
},
}
};
emailTemplates.resetPassword = {
@ -39,21 +41,21 @@ emailTemplates.resetPassword = {
return `[${name}] Reset Your Password`;
},
html(user, url) {
return templateToHTML(getPrivateFile('email-templates/reset-password.html'), {
return templateToHTML(getPrivateFile(getFileNameOfLang('email-templates', 'reset-password', 'html', user.lang)), {
firstName: user.profile.name.first,
applicationName: name,
emailAddress: user.emails[0].address,
resetUrl: url.replace('#/', ''),
resetUrl: url.replace('#/', '')
});
},
text(user, url) {
const urlWithoutHash = url.replace('#/', '');
if (Meteor.isDevelopment) console.info(`Reset Password Link: ${urlWithoutHash}`); // eslint-disable-line
return templateToText(getPrivateFile('email-templates/reset-password.txt'), {
return templateToText(getPrivateFile(getFileNameOfLang('email-templates', 'reset-password', 'txt', user.lang)), {
firstName: user.profile.name.first,
applicationName: name,
emailAddress: user.emails[0].address,
resetUrl: urlWithoutHash,
resetUrl: urlWithoutHash
});
},
}
};

View file

@ -3,7 +3,15 @@ import sendWelcomeEmail from '../../../api/Users/server/send-welcome-email';
Accounts.onCreateUser((options, user) => {
const userToCreate = user;
if (options.profile) userToCreate.profile = options.profile;
sendWelcomeEmail(options, user);
console.log(JSON.stringify(user));
console.log(JSON.stringify(options));
if (options.profile) {
userToCreate.profile = options.profile;
userToCreate.lang = options.profile.lang;
delete options.profile.lang;
} else {
// TODO others (google, etc) ?
}
sendWelcomeEmail(options, userToCreate);
return userToCreate;
});