Refine translation

This commit is contained in:
Wolfgang Huß 2022-10-10 17:51:40 +02:00
parent ad719dde43
commit f90f981566
8 changed files with 73 additions and 109 deletions

View File

@ -1,23 +1,22 @@
doctype html
html(lang="en")
head
title= subject
title= t('emails.accountMultiRegistration.subject')
body
h1(style='margin-bottom: 24px;')= t('emails.accountMultiRegistration.subject')
#container.col
//- p(style='margin-bottom: 24px;') Hallo #{firstName} #{lastName},
p(style='margin-bottom: 24px;')= t('emails.accountMultiRegistration.helloName', { firstName, lastName })
p Deine E-Mail-Adresse wurde soeben erneut benutzt, um bei Gradido ein Konto zu registrieren.
p= t('emails.accountMultiRegistration.emailReused')
br
| Es existiert jedoch zu deiner E-Mail-Adresse schon ein Konto.
p Klicke bitte auf den folgenden Link, falls du dein Passwort vergessen haben solltest:
span= t('emails.accountMultiRegistration.emailExists')
p= t('emails.accountMultiRegistration.onForgottenPasswordClickLink')
br
a(href=resendLink) #{resendLink}
br
| oder kopiere den obigen Link in dein Browserfenster.
p Wenn du nicht derjenige bist, der sich versucht hat erneut zu registrieren, wende dich bitte an unseren support:
span= t('emails.accountMultiRegistration.onForgottenPasswordCopyLink')
p= t('emails.accountMultiRegistration.ifYouAreNotTheOne')
br
a(href='https://gradido.net/de/contact/') https://gradido.net/de/contact/
p(style='margin-top: 24px;') Mit freundlichen Grüßen,
p(style='margin-top: 24px;')= t('emails.accountMultiRegistration.sincerelyYours')
br
| dein Gradido-Team
span= t('emails.accountMultiRegistration.yourGradidoTeam')

View File

@ -1 +1 @@
= `${t('emails.accountMultiRegistration.subject')}`
= t('emails.accountMultiRegistration.subject')

View File

@ -1,6 +1,8 @@
import { backendLogger as logger } from '@/server/logger'
import path from 'path'
import { createTransport } from 'nodemailer'
import Email from 'email-templates'
import i18n from 'i18n'
import CONFIG from '@/config'
@ -10,21 +12,15 @@ export const sendEmailTranslated = async (params: {
cc?: string
}
template: string
locals: Record<string, unknown>
locals: Record<string, string>
}): Promise<boolean> => {
// Wolle: logger.info(
// `send Email: to=${params.receiver.to}` +
// (params.receiver.cc ? `, cc=${params.receiver.cc}` : '') +
// `, subject=${params.locals.subject}, text=${params.text}`,
// )
i18n.setLocale(params.locals.locale)
logger.info(
`send Email: to=${params.receiver.to}` +
(params.receiver.cc ? `, cc=${params.receiver.cc}` : '') +
`, subject=${params.locals.subject}`,
`, subject=${i18n.__('emails.' + params.template + '.subject')}`,
)
// Wolle: console.log('sendEmailTranslated !!!')
// Wolle:
console.log('params: ', params)
if (!CONFIG.EMAIL) {
logger.info(`Emails are disabled via config...`)
@ -53,44 +49,25 @@ export const sendEmailTranslated = async (params: {
},
// uncomment below to send emails in development/test env:
// send: true,
// Wolle: transport: {
// transport: {
// jsonTransport: true,
// },
transport,
// uncomment below to open send emails in the browser
// Wolle:
// preview: {
// open: {
// app: 'firefox',
// wait: false,
// },
// },
i18n: {
locales: ['en', 'de'],
directory: '/app/src/locales',
defaultLocale: 'en',
},
// i18n,
})
email
.send({
template: '/app/src/emails/' + params.template,
message: {
...params.receiver,
},
// Wolle: locals: params.locals,
locals: {
...params.locals,
locale: 'de',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
$t(key: any, options: any) {
// <------ THIS IS OUR OWN TRANSLATION HELPER
return options.data.root.t(
{ phrase: key, locale: options.data.root.locale },
options.hash,
)
},
},
template: path.join(__dirname, params.template),
message: params.receiver,
locals: params.locals,
})
.then((result: unknown) => {
logger.info('Send email successfully.')

View File

@ -5,13 +5,13 @@ export const sendAccountMultiRegistrationEmail = (data: {
firstName: string
lastName: string
email: string
language: string
}): Promise<boolean> => {
// Wolle: console.log('sendAccountMultiRegistrationEmail !!!')
return sendEmailTranslated({
receiver: { to: `${data.firstName} ${data.lastName} <${data.email}>` },
template: 'accountMultiRegistration',
locals: {
subject: 'Gradido: Erneuter Registrierungsversuch mit deiner E-Mail',
locale: data.language,
firstName: data.firstName,
lastName: data.lastName,
resendLink: CONFIG.EMAIL_LINK_FORGOTPASSWORD,

View File

@ -18,7 +18,6 @@ import { klicktippNewsletterStateMiddleware } from '@/middleware/klicktippMiddle
import { OptInType } from '@enum/OptInType'
import { sendResetPasswordEmail as sendResetPasswordEmailMailer } from '@/mailer/sendResetPasswordEmail'
import { sendAccountActivationEmail } from '@/mailer/sendAccountActivationEmail'
// Wolle: import { sendAccountMultiRegistrationEmail } from '@/mailer/sendAccountMultiRegistrationEmail'
import { sendAccountMultiRegistrationEmail } from '@/emails/sendEmailVariants'
import { klicktippSignIn } from '@/apis/KlicktippController'
import { RIGHTS } from '@/auth/RIGHTS'
@ -430,12 +429,11 @@ export class UserResolver {
user.publisherId = publisherId
logger.debug('partly faked user=' + user)
// Wolle: console.log('createUser !!! already exists …')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const emailSent = await sendAccountMultiRegistrationEmail({
firstName,
lastName,
email,
language,
})
const eventSendAccountMultiRegistrationEmail = new EventSendAccountMultiRegistrationEmail()
eventSendAccountMultiRegistrationEmail.userId = foundUser.id

View File

@ -1,9 +1,15 @@
{
"emails": {
"accountMultiRegistration": {
"subject": "Gradido: Erneuter Registrierungsversuch mit deiner E-Mail"
"emailExists": "Es existiert jedoch zu deiner E-Mail-Adresse schon ein Konto.",
"emailReused": "Deine E-Mail-Adresse wurde soeben erneut benutzt, um bei Gradido ein Konto zu registrieren.",
"helloName": "Hallo {firstName} {lastName}",
"ifYouAreNotTheOne": "Wenn du nicht derjenige bist, der sich versucht hat erneut zu registrieren, wende dich bitte an unseren support:",
"onForgottenPasswordClickLink": "Klicke bitte auf den folgenden Link, falls du dein Passwort vergessen haben solltest:",
"onForgottenPasswordCopyLink": "oder kopiere den obigen Link in dein Browserfenster.",
"sincerelyYours": "Mit freundlichen Grüßen,",
"subject": "Gradido: Erneuter Registrierungsversuch mit deiner E-Mail",
"yourGradidoTeam": "dein Gradido-Team"
}
},
"emails.accountMultiRegistration.subject": "Gradido: Erneuter Registrierungsversuch mit deiner E-Mail",
"emails.accountMultiRegistration.helloName": "Hallo {firstName} {lastName}"
}
}

View File

@ -1,9 +1,15 @@
{
"emails": {
"accountMultiRegistration": {
"subject": "Gradido: Try To Register Again With Your Email"
}
},
"emails.accountMultiRegistration.subject": "Gradido: Try To Register Again With Your Email",
"emails.accountMultiRegistration.helloName": "Hello {firstName} {lastName}"
"emails": {
"accountMultiRegistration": {
"emailExists": "However, an account already exists for your email address.",
"emailReused": "Your email address has just been used again to register an account with Gradido.",
"helloName": "Hello {firstName} {lastName}",
"ifYouAreNotTheOne": "If you are not the one who tried to register again, please contact our support:",
"onForgottenPasswordClickLink": "Please click on the following link if you have forgotten your password:",
"onForgottenPasswordCopyLink": "or copy the link above into your browser window.",
"sincerelyYours": "Sincerely yours,",
"subject": "Gradido: Try To Register Again With Your Email",
"yourGradidoTeam": "your Gradido team"
}
}
}

View File

@ -26,7 +26,8 @@ import { apolloLogger } from './logger'
import { Logger } from 'log4js'
// i18n
// Wolle: import { I18n } from 'i18n'
import path from 'path'
import i18n from 'i18n'
// TODO implement
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
@ -65,6 +66,31 @@ const createServer = async (
// bodyparser urlencoded for elopage
app.use(express.urlencoded({ extended: true }))
// i18n
app.use(i18n.init)
i18n.configure({
locales: ['en', 'de'],
defaultLocale: 'en',
retryInDefaultLocale: false,
directory: path.join(__dirname, '..', 'locales'),
autoReload: true,
updateFiles: false,
objectNotation: true,
// logDebugFn: logger.debug,
// logWarnFn: logger.info,
// logErrorFn: logger.error,
api: {
__: 't', // now req.__ becomes req.t
__n: 'tn', // and req.__n can be called as req.tn
},
register: global,
mustacheConfig: {
tags: ['{', '}'],
disable: false,
},
})
i18n.setLocale('en')
// Elopage Webhook
app.post('/hook/elopage/' + CONFIG.WEBHOOK_ELOPAGE_SECRET, elopageWebhook)
@ -83,54 +109,6 @@ const createServer = async (
)
logger.debug('createServer...successful')
// i18n
// const i18n = new I18n({
// locales: ['en', 'de'],
// directory: '/app/src/locales',
// })
// Wolle: const i18n = new I18n({
// // phrases: {},
// logDebugFn: logger.debug,
// logWarnFn: logger.info,
// logErrorFn: logger.error,
// directory: '/app/src/locales',
// locales: ['en', 'de'],
// // cookie: 'locale',
// // cookieOptions: {
// // // Disable signed cookies in NODE_ENV=test
// // signed: process.env.NODE_ENV !== 'test'
// // },
// // expiryMs: 31556952000, // one year in ms
// // indent: ' ',
// // defaultLocale: 'en',
// // // `process.env.I18N_SYNC_FILES`
// // syncFiles: true,
// // // `process.env.I18N_AUTO_RELOAD`
// // autoReload: false,
// // // `process.env.I18N_UPDATE_FILES`
// // updateFiles: true,
// // api: {
// // __: 't',
// // __n: 'tn',
// // __l: 'tl',
// // __h: 'th',
// // __mf: 'tmf'
// // },
// // register: i18n.api,
// // lastLocaleField: 'last_locale',
// // ignoredRedirectGlobs: [],
// // redirectIgnoresNonGetMethods: true,
// // // <https://github.com/ljharb/qs>
// // stringify: {
// // addQueryPrefix: true,
// // format: 'RFC1738',
// // arrayFormat: 'indices'
// // },
// // redirectTLDS: true,
// // // function that allows using a custom logic for locale detection (can return promise)
// // detectLocale: null
// })
return { apollo, app, con }
}