mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Implement 'i18n' better into the server
This commit is contained in:
parent
cc02b19fb5
commit
a73cca0ab4
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
29
backend/src/server/localization.ts
Normal file
29
backend/src/server/localization.ts
Normal 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 }
|
||||
Loading…
x
Reference in New Issue
Block a user