From 7091e50775494b4d5df918a16d155f9afc1e34e0 Mon Sep 17 00:00:00 2001 From: kernoeb Date: Thu, 25 Apr 2024 18:34:02 +0200 Subject: [PATCH] chore: fix i18n --- server/resources/messages-en.json | 4 +++- server/resources/messages-fr.json | 4 +++- server/routers/messages.js | 6 ++++-- server/utils/i18n.js | 12 ++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/server/resources/messages-en.json b/server/resources/messages-en.json index 9e26dfe..f8288e2 100644 --- a/server/resources/messages-en.json +++ b/server/resources/messages-en.json @@ -1 +1,3 @@ -{} \ No newline at end of file +{ + "notifications.message": "Answer by {{userName}} to your comment on {{comment}}" +} diff --git a/server/resources/messages-fr.json b/server/resources/messages-fr.json index 9e26dfe..63585ac 100644 --- a/server/resources/messages-fr.json +++ b/server/resources/messages-fr.json @@ -1 +1,3 @@ -{} \ No newline at end of file +{ + "notifications.message": "Réponse de {{userName}} à votre commentaire : {{content}}" +} diff --git a/server/routers/messages.js b/server/routers/messages.js index 5c3238b..a586e8a 100644 --- a/server/routers/messages.js +++ b/server/routers/messages.js @@ -46,8 +46,10 @@ router.post('', asyncWrap(async (req, res) => { send({ sender: { type: 'organization', id: req.user.activeAccount.id }, topic: { key: 'social::message-posted' }, - title: { en: 'New message posted' }, - extra: { message }, + title: req.__all('notifications.message', { + userName: req.body.responseTo.user.name, + content: req.body.content + }), recipient: { id: req.body.responseTo.user.id }, outputs: [] }).catch(console.error) diff --git a/server/utils/i18n.js b/server/utils/i18n.js index 37afa9f..63276ec 100644 --- a/server/utils/i18n.js +++ b/server/utils/i18n.js @@ -7,10 +7,22 @@ const messages = { en: { ...fr, ...require('../resources/messages-en.json') } } +function getObjectI18n (__, key, args) { + return { + fr: __({ phrase: key, locale: 'fr' }, args), + en: __({ phrase: key, locale: 'en' }, args), + es: __({ phrase: key, locale: 'es' }, args), + pt: __({ phrase: key, locale: 'pt' }, args), + it: __({ phrase: key, locale: 'it' }, args), + de: __({ phrase: key, locale: 'de' }, args) + } +} + exports.middleware = (req, res, next) => { const locales = acceptLangParser.parse(req.get('Accept-Language')) const localeCode = req.cookies.i18n_lang || (locales && locales[0] && locales[0].code) || config.i18n.defaultLocale req.locale = localeCode req.messages = messages[localeCode] || messages.fr + req.__all = (key, args) => getObjectI18n(req.__, key, args) next() }