From c67609b4177bd558d864b4559f0a778d759a4b33 Mon Sep 17 00:00:00 2001 From: vjrj Date: Tue, 23 Jan 2018 12:50:04 +0100 Subject: [PATCH] More work in email translations --- .../api/Users/server/send-welcome-email.js | 4 +-- imports/modules/server/send-email.js | 3 ++ .../server/accounts/email-templates.js | 28 ++++++++++++------- .../startup/server/accounts/on-create-user.js | 8 ++++-- imports/startup/server/email.js | 2 +- private/pages/privacy-es.md | 2 +- public/locales/en/common.json | 5 ++-- public/locales/es/common.json | 4 ++- settings-development-sample.json | 1 + 9 files changed, 37 insertions(+), 20 deletions(-) diff --git a/imports/api/Users/server/send-welcome-email.js b/imports/api/Users/server/send-welcome-email.js index 3c11679..c9eac03 100644 --- a/imports/api/Users/server/send-welcome-email.js +++ b/imports/api/Users/server/send-welcome-email.js @@ -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, diff --git a/imports/modules/server/send-email.js b/imports/modules/server/send-email.js index 02a6f59..8d6fc32 100644 --- a/imports/modules/server/send-email.js +++ b/imports/modules/server/send-email.js @@ -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 diff --git a/imports/startup/server/accounts/email-templates.js b/imports/startup/server/accounts/email-templates.js index 0daf6b3..fdb25a3 100644 --- a/imports/startup/server/accounts/email-templates.js +++ b/imports/startup/server/accounts/email-templates.js @@ -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 = ''; -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 }); diff --git a/imports/startup/server/accounts/on-create-user.js b/imports/startup/server/accounts/on-create-user.js index 4b22f5e..fa2a99e 100644 --- a/imports/startup/server/accounts/on-create-user.js +++ b/imports/startup/server/accounts/on-create-user.js @@ -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; }); diff --git a/imports/startup/server/email.js b/imports/startup/server/email.js index 08826c4..c514fff 100644 --- a/imports/startup/server/email.js +++ b/imports/startup/server/email.js @@ -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 */ diff --git a/private/pages/privacy-es.md b/private/pages/privacy-es.md index a15b9cd..c494ca4 100644 --- a/private/pages/privacy-es.md +++ b/private/pages/privacy-es.md @@ -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** diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 4b3c391..328b93a 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -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 & 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 of this site", - "Bienvenid@!": "Welcome!" + "Bienvenid@!": "Welcome!", + "Verifica tu dirección de correo": "Verify Your Email Address" } diff --git a/public/locales/es/common.json b/public/locales/es/common.json index 85a85fe..1d6bb2c 100644 --- a/public/locales/es/common.json +++ b/public/locales/es/common.json @@ -227,5 +227,7 @@ "Última actualización, {{when}}": "Última actualización, {{when}}", "termsAccept": "Acepto las <1>condiciones de servicio 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" } diff --git a/settings-development-sample.json b/settings-development-sample.json index 5b9be59..e8cb633 100644 --- a/settings-development-sample.json +++ b/settings-development-sample.json @@ -13,6 +13,7 @@ "private": { "testEmail": "someone@example.com", "testMailer": false, + "debugMailer": false, "MAIL_URL": "", "OAuth": { "facebook": {