Implement 'i18n' better into the server

This commit is contained in:
Wolfgang Huß 2022-11-10 15:23:51 +01:00
parent cc02b19fb5
commit a73cca0ab4
3 changed files with 33 additions and 26 deletions

View File

@ -60,7 +60,7 @@ export const sendEmailTranslated = async (params: {
// wait: false,
// },
// },
// i18n, // seems not to be needed
// i18n, // is only needed if you don't install i18n
})
email

View File

@ -26,8 +26,7 @@ import { apolloLogger } from './logger'
import { Logger } from 'log4js'
// i18n
import path from 'path'
import i18n from 'i18n'
import { i18n } from './localization'
// TODO implement
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
@ -38,6 +37,7 @@ const createServer = async (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
context: any = serverContext,
logger: Logger = apolloLogger,
localization: any = i18n,
): Promise<ServerDef> => {
logger.addContext('user', 'unknown')
logger.debug('createServer...')
@ -68,29 +68,7 @@ const createServer = async (
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, // if this is activated the seeding hangs at the very end
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')
app.use(localization.init)
// Elopage Webhook
app.post('/hook/elopage/' + CONFIG.WEBHOOK_ELOPAGE_SECRET, elopageWebhook)

View File

@ -0,0 +1,29 @@
import path from 'path'
import { backendLogger } from './logger'
import i18n from 'i18n'
i18n.configure({
locales: ['en', 'de'],
defaultLocale: 'en',
retryInDefaultLocale: false,
directory: path.join(__dirname, '..', 'locales'),
// autoReload: true, // if this is activated the seeding hangs at the very end
updateFiles: false,
objectNotation: true,
logDebugFn: (msg) => backendLogger.debug(msg),
logWarnFn: (msg) => backendLogger.info(msg),
logErrorFn: (msg) => backendLogger.error(msg),
// this api is needed for email-template pug files
api: {
__: 't', // now req.__ becomes req.t
__n: 'tn', // and req.__n can be called as req.tn
},
register: global,
mustacheConfig: {
tags: ['{', '}'],
disable: false,
},
})
// Wolle: i18n.setLocale('en')
export { i18n }