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

@ -2,13 +2,13 @@ import i18n from 'i18next';
import sendEmail from '../../../modules/server/send-email';
import getOAuthProfile from '../../../modules/get-oauth-profile';
export default (options, user) => {
export default (options, user, lang) => {
const OAuthProfile = getOAuthProfile(options, user);
i18n.changeLanguage(lang);
const applicationName = i18n.t('AppName');
const firstName = OAuthProfile ? OAuthProfile.name.first : options.profile.name.first;
const emailAddress = OAuthProfile ? OAuthProfile.email : options.email;
const { lang } = user.lang;
return sendEmail({
to: emailAddress,

View file

@ -10,6 +10,8 @@ import i18n from 'i18next';
const sendEmail = (options, { resolve, reject }) => {
try {
Meteor.defer(() => {
// console.log(`Current user lang ${options.lang}`);
i18n.changeLanguage(options.lang);
// Meteor email options:
// basic: from, to/cc/bcc/replyTo, subject, html, text,
// others: watchHtml, icalEvent, headers, attachments, mailComposer, inReplyTo, references, messageId
@ -33,6 +35,7 @@ export default ({
if (text || html || template) {
return new Promise((resolve, reject) => {
sendEmail({
lang,
...rest,
text: template ? templateToText(getPrivateFile(getFileNameOfLang('email-templates', template, 'txt', lang)), (templateVars || {})) : text,
html: template ? templateToHTML(getPrivateFile(getFileNameOfLang('email-templates', template, 'html', lang)), (templateVars || {})) : html

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;
});

View file

@ -38,7 +38,7 @@ const MailQueue = new MailTime({
}
return `${i18n.t('AppName')} <${transport.options.auth.user}>`;
},
debug: true,
debug: Meteor.settings.private.debugMailer,
concatEmails: true, // Concatenate emails to the same addressee
concatSubject: `${i18n.t('Nuevas notificaciones de {{app}}', { app: i18n.t('AppName') })}`,
/* eslint-disable */

View file

@ -6,7 +6,7 @@ Esta página se utiliza para informar a los visitantes del sitio web sobre nuest
Si elige usar nuestro Servicio, acepta la recopilación y el uso de la información en relación con esta política. La información personal que recopilamos se usa para proporcionar y mejorar el servicio. No usaremos ni compartiremos su información con nadie, excepto según se describe en esta Política de privacidad.
Los términos utilizados en esta Política de privacidad tienen los mismos significados que en nuestros [Términos y condiciones](/terms), a los que se puede acceder en "Tod@s contra incendio" a menos que se defina lo contrario en esta Política de privacidad.
Los términos utilizados en esta Política de privacidad tienen los mismos significados que en nuestros [Términos y condiciones](/terms), a los que se puede acceder en "Tod@s contra el fuego" a menos que se defina lo contrario en esta Política de privacidad.
**Recopilación y uso de información**

View file

@ -52,7 +52,7 @@
"Repite tu nueva contraseña, por favor.": "Repeat your new password, please.",
"Mmmm, tus contraseñas no coinciden. Inténtalo otra vez": "Hmm, your passwords don't match. Try again",
"Para resetear tu contraseña, introduce una nueva debajo. Iniciarás la sesión con la nueva contraseña.": "To reset your password, enter a new one below. You will be logged in with your new password.",
"Resetea tu contraseña": "Reset Password",
"Resetea tu contraseña": "Reset your Password",
"Repite la nueva contraseña": "Repeat New Password",
"Resetea la contraseña y entra": "Reset Password &amp; Login",
"Imágenes capturadas por los satélites de la NASA muestran el humo de grandes incendios que se extienden sobre el Océano Pacífico. La actividad del fuego está delineada en rojo.": "Images captured by NASA satellites show the smoke of large fires spreading over the Pacific Ocean. Fire activity is outlined in red.",
@ -157,5 +157,6 @@
"not-found": "Oops: This page doesn't exist",
"Más información sobre este fuego": "More information about this fire",
"termsAccept": "I accept the <1>conditions of service</1> of this site",
"Bienvenid@!": "Welcome!"
"Bienvenid@!": "Welcome!",
"Verifica tu dirección de correo": "Verify Your Email Address"
}

View file

@ -227,5 +227,7 @@
"Última actualización, {{when}}": "Última actualización, {{when}}",
"termsAccept": "Acepto las <1>condiciones de servicio</1> de este sitio",
"Bienvenid@!": "Bienvenid@!",
"Has iniciado sesión con {{service}} usando la dirección de correo {{email}}.": "Has iniciado sesión con {{service}} usando la dirección de correo {{email}}."
"Has iniciado sesión con {{service}} usando la dirección de correo {{email}}.": "Has iniciado sesión con {{service}} usando la dirección de correo {{email}}.",
"Verifica tu dirección de correo":
"Verifica tu dirección de correo"
}

View file

@ -13,6 +13,7 @@
"private": {
"testEmail": "someone@example.com",
"testMailer": false,
"debugMailer": false,
"MAIL_URL": "",
"OAuth": {
"facebook": {