More work in email translations

This commit is contained in:
vjrj 2018-01-23 12:50:04 +01:00
parent af042b8722
commit c67609b417
9 changed files with 37 additions and 20 deletions

View file

@ -6,21 +6,27 @@ 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 = i18n.t('AppName');
const name = (lang) => {
i18n.changeLanguage(lang);
return i18n.t('AppName');
};
const email = '<noreply@comunes.org>';
const from = `${name} ${email}`;
const from = `${name('en')} ${email}`;
// const from = 'noreply@comunes.org';
const emailTemplates = Accounts.emailTemplates;
emailTemplates.siteName = name;
emailTemplates.from = from;
emailTemplates.verifyEmail = {
subject() {
return `[${name}] Verify Your Email Address`;
subject(user) {
i18n.changeLanguage(user.lang);
const msg = i18n.t('Verifica tu dirección de correo');
return `[${name(user.lang)}] ${msg}`;
},
html(user, url) {
return templateToHTML(getPrivateFile(getFileNameOfLang('email-templates', 'verify-email', 'html', user.lang)), {
applicationName: name,
applicationName: name(user.lang),
firstName: user.profile.name.first,
verifyUrl: url.replace('#/', '')
});
@ -29,7 +35,7 @@ emailTemplates.verifyEmail = {
const urlWithoutHash = url.replace('#/', '');
if (Meteor.isDevelopment) console.info(`Verify Email Link: ${urlWithoutHash}`); // eslint-disable-line
return templateToText(getPrivateFile(getFileNameOfLang('email-templates', 'verify-email', 'txt', user.lang)), {
applicationName: name,
applicationName: name(user.lang),
firstName: user.profile.name.first,
verifyUrl: urlWithoutHash
});
@ -37,13 +43,15 @@ emailTemplates.verifyEmail = {
};
emailTemplates.resetPassword = {
subject() {
return `[${name}] Reset Your Password`;
subject(user) {
i18n.changeLanguage(user.lang);
const msg = i18n.t('Resetea tu contraseña');
return `[${name(user.lang)}] ${msg}`;
},
html(user, url) {
return templateToHTML(getPrivateFile(getFileNameOfLang('email-templates', 'reset-password', 'html', user.lang)), {
firstName: user.profile.name.first,
applicationName: name,
applicationName: name(user.lang),
emailAddress: user.emails[0].address,
resetUrl: url.replace('#/', '')
});
@ -53,7 +61,7 @@ emailTemplates.resetPassword = {
if (Meteor.isDevelopment) console.info(`Reset Password Link: ${urlWithoutHash}`); // eslint-disable-line
return templateToText(getPrivateFile(getFileNameOfLang('email-templates', 'reset-password', 'txt', user.lang)), {
firstName: user.profile.name.first,
applicationName: name,
applicationName: name(user.lang),
emailAddress: user.emails[0].address,
resetUrl: urlWithoutHash
});

View file

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