Implement translation, very first approach

This commit is contained in:
Wolfgang Huß 2022-10-10 11:54:09 +02:00
parent d6300c373c
commit ad719dde43
8 changed files with 100 additions and 7 deletions

View File

@ -19,6 +19,7 @@
},
"dependencies": {
"@types/email-templates": "^10.0.1",
"@types/i18n": "^0.13.4",
"@types/jest": "^27.0.2",
"@types/lodash.clonedeep": "^4.5.6",
"@types/uuid": "^8.3.4",
@ -33,6 +34,7 @@
"email-templates": "^10.0.1",
"express": "^4.17.1",
"graphql": "^15.5.1",
"i18n": "^0.15.1",
"jest": "^27.2.4",
"jsonwebtoken": "^8.5.1",
"lodash.clonedeep": "^4.5.0",

View File

@ -3,9 +3,10 @@ html(lang="en")
head
title= subject
body
h1(style='margin-bottom: 24px;') Gradido: Erneuter Registrierungsversuch mit deiner E-Mail
h1(style='margin-bottom: 24px;')= t('emails.accountMultiRegistration.subject')
#container.col
p(style='margin-bottom: 24px;') Hallo #{firstName} #{lastName},
//- 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.
br
| Es existiert jedoch zu deiner E-Mail-Adresse schon ein Konto.

View File

@ -1 +1 @@
= `Gradido: Erneuter Registrierungsversuch mit deiner E-Mail`
= `${t('emails.accountMultiRegistration.subject')}`

View File

@ -23,7 +23,8 @@ export const sendEmailTranslated = async (params: {
`, subject=${params.locals.subject}`,
)
// Wolle: console.log('sendEmailTranslated !!!')
// Wolle: console.log('params: ', params)
// Wolle:
console.log('params: ', params)
if (!CONFIG.EMAIL) {
logger.info(`Emails are disabled via config...`)
@ -64,6 +65,11 @@ export const sendEmailTranslated = async (params: {
// wait: false,
// },
// },
i18n: {
locales: ['en', 'de'],
directory: '/app/src/locales',
defaultLocale: 'en',
},
})
email
@ -73,7 +79,18 @@ export const sendEmailTranslated = async (params: {
...params.receiver,
},
// Wolle: locals: params.locals,
locals: { ...params.locals, locale: 'de' },
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,
)
},
},
})
.then((result: unknown) => {
logger.info('Send email successfully.')

View File

@ -3,5 +3,7 @@
"accountMultiRegistration": {
"subject": "Gradido: Erneuter Registrierungsversuch mit deiner E-Mail"
}
}
},
"emails.accountMultiRegistration.subject": "Gradido: Erneuter Registrierungsversuch mit deiner E-Mail",
"emails.accountMultiRegistration.helloName": "Hallo {firstName} {lastName}"
}

View File

@ -3,5 +3,7 @@
"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}"
}

View File

@ -25,6 +25,9 @@ import { Connection } from '@dbTools/typeorm'
import { apolloLogger } from './logger'
import { Logger } from 'log4js'
// i18n
// Wolle: import { I18n } from 'i18n'
// TODO implement
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
@ -79,6 +82,55 @@ const createServer = async (
`running with PRODUCTION=${CONFIG.PRODUCTION}, sending EMAIL enabled=${CONFIG.EMAIL} and EMAIL_TEST_MODUS=${CONFIG.EMAIL_TEST_MODUS} ...`,
)
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 }
}

View File

@ -972,6 +972,11 @@
resolved "https://registry.yarnpkg.com/@types/http-errors/-/http-errors-1.8.1.tgz#e81ad28a60bee0328c6d2384e029aec626f1ae67"
integrity sha512-e+2rjEwK6KDaNOm5Aa9wNGgyS9oSZU/4pfSMMPYNOfjvFI0WVXm29+ITRFr6aKDvvKo7uU1jV68MW4ScsfDi7Q==
"@types/i18n@^0.13.4":
version "0.13.4"
resolved "https://registry.yarnpkg.com/@types/i18n/-/i18n-0.13.4.tgz#fe3d27d08337f9d4a972d1f460d1471d6f79e163"
integrity sha512-PN4ZsplbpHZ2eaYixFNWkZKN51pcB02K2UKvqHVbrzq2jTO0sChPMuKKYAW1ZbElyHUvPgFeYsz9rqktChGyMw==
"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz#4ba8ddb720221f432e443bd5f9117fd22cfd4762"
@ -3427,6 +3432,18 @@ i18n@^0.15.0:
math-interval-parser "^2.0.1"
mustache "^4.2.0"
i18n@^0.15.1:
version "0.15.1"
resolved "https://registry.yarnpkg.com/i18n/-/i18n-0.15.1.tgz#68fb8993c461cc440bc2485d82f72019f2b92de8"
integrity sha512-yue187t8MqUPMHdKjiZGrX+L+xcUsDClGO0Cz4loaKUOK9WrGw5pgan4bv130utOwX7fHE9w2iUeHFalVQWkXA==
dependencies:
"@messageformat/core" "^3.0.0"
debug "^4.3.3"
fast-printf "^1.6.9"
make-plural "^7.0.0"
math-interval-parser "^2.0.1"
mustache "^4.2.0"
iconv-lite@0.4.24:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"