Skip to content

Commit f95addd

Browse files
committed
fix: Improved translations
1 parent 9178e9b commit f95addd

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

server/i18n/en.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22
"noIDProvided": "No ID provided",
33
"nothingToExport": "Nothing to export",
44
"unauthorized": "Unauthorized",
5+
"missingLogin": "Missing login",
56
"missingPassword": "Missing password",
7+
"missingToken": "Missing token",
68
"passwordUpdated": "Password updated",
7-
"tokenExpired": "Token expired",
9+
"sessionExpiredPleaseReconnect": "Session expired, please reconnect",
810
"invalidPassword": "Invalid password",
11+
"resetPasswordEmail": "Reset password email",
12+
"cannotSendOldPassword": "We cannot simply send you your old password. A unique link to reset your password has been generated for you. To reset your password, click the following button and follow the instructions.",
13+
"resetPassword": "Reset password",
914
"passwordResetMessage": "If the button doesnt work copy and paste the following in your browser",
1015
"resetYourPassword": "Reset your password",
1116
"clickLinkToResetPassword": "Click the following link to reset your password",
1217
"emailNotSent": "Email not sent",
1318
"emailSent": "Email sent",
1419
"tokenValid": "Token valid",
15-
"invalidToken": "Invalid token"
20+
"invalidToken": "Invalid token",
21+
"unableToConnectToMailServer": "Unable to connect to mail server"
1622
}

server/i18n/fr.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22
"noIDProvided": "ID manquant",
33
"nothingToExport": "Rien à exporter",
44
"unauthorized": "Non autorisé",
5+
"missingLogin": "Identifiant manquant",
56
"missingPassword": "Mot de passe manquant",
7+
"missingToken": "Token manquant",
68
"passwordUpdated": "Mot de passe mis à jour avec succès",
7-
"tokenExpired": "Token expiré",
9+
"sessionExpiredPleaseReconnect": "Session expirée, veuillez vous reconnecter",
810
"invalidPassword": "Mot de passe invalide",
11+
"resetPasswordEmail": "Email de réinitialisation de mot de passe",
12+
"cannotSendOldPassword": "Nous ne pouvons pas simplement vous envoyer votre ancien mot de passe. Un lien unique pour réinitialiser votre mot de passe a été généré pour vous. Pour réinitialiser votre mot de passe, cliquez sur le bouton suivant et suivez les instructions.",
13+
"resetPassword": "Réinitialiser le mot de passe",
914
"passwordResetMessage": "Si le bouton ne fonctionne pas, copiez et collez ce qui suit dans votre navigateur",
1015
"resetYourPassword": "Réinitialiser votre mot de passe",
1116
"clickLinkToResetPassword": "Cliquez sur le lien suivant pour réinitialiser votre mot de passe",
1217
"emailNotSent": "Email non envoyé",
1318
"emailSent": "Email envoyé",
1419
"tokenValid": "Token valide",
15-
"invalidToken": "Token invalide"
20+
"invalidToken": "Token invalide",
21+
"unableToConnectToMailServer": "Impossible de se connecter au serveur de messagerie"
1622
}

server/src/controllers/Users.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ const authenticate = (prisma: PrismaClient) => async (
2525
const { login, password } = req.body;
2626

2727
if (!login) {
28-
throw new Error('Missing Login');
28+
throw new Error(t('missingLogin'));
2929
}
3030

3131
if (!password) {
32-
throw new Error('Missing Password');
32+
throw new Error(t('missingPassword'));
3333
}
3434

3535
const user = await prisma.user.findFirstOrThrow({
@@ -53,7 +53,7 @@ const authenticate = (prisma: PrismaClient) => async (
5353
}
5454

5555
// Token is expired, throw error
56-
throw new Error(t('tokenExpired'));
56+
throw new Error(t('sessionExpiredPleaseReconnect'));
5757
}
5858

5959
// Check password against DB
@@ -159,16 +159,13 @@ const sendPasswordResetEmail = (prisma: PrismaClient) => async (
159159
// Reset URL
160160
const url = `${req.protocol}://${req.hostname}/login?login=${encodeURIComponent(user.login)}&reset=${encodeURIComponent(token)}`;
161161

162-
// Mail message
163-
const message = t('passwordResetMessage');
164-
165162
// Send email
166163
const mailInfo = await MailUtils.sendMail({
167164
from: MAIL_SENDER,
168165
to: user.person.email,
169166
subject: t('resetYourPassword'),
170167
text: `${t('clickLinkToResetPassword')}: ${url}`,
171-
html: MailUtils.passwordResetTemplate(url, message),
168+
html: MailUtils.passwordResetTemplate(url),
172169
});
173170

174171
if (mailInfo.accepted.length === 0) {
@@ -229,15 +226,15 @@ const resetPassword = (prisma: PrismaClient) => async (
229226
const { code, login, password } = req.body;
230227

231228
if (!code) {
232-
throw new Error('Missing token');
229+
throw new Error(t('missingToken'));
233230
}
234231

235232
if (!login) {
236-
throw new Error('Missing login');
233+
throw new Error(t('missingLogin'));
237234
}
238235

239236
if (!password) {
240-
throw new Error('Missing password');
237+
throw new Error(t('missingPassword'));
241238
}
242239

243240
const user = await prisma.user.findFirstOrThrow({

server/src/utils/MailUtils.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { t } from 'i18next';
12
import { createTransport } from 'nodemailer';
23
import Mail from 'nodemailer/lib/mailer';
34

@@ -83,12 +84,12 @@ ${action}
8384
* @param url
8485
* @param message
8586
*/
86-
const passwordResetTemplate = (url: string, message: string) => /* html */`<!DOCTYPE html>
87+
const passwordResetTemplate = (url: string) => /* html */`<!DOCTYPE html>
8788
<html lang="en-US">
8889
<head>
8990
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
90-
<title>Reset Password Email</title>
91-
<meta name="description" content="Reset Password Email Template." />
91+
<title>${t('resetPasswordEmail')}</title>
92+
<meta name="description" content="${t('resetPasswordEmail')}" />
9293
<style type="text/css">
9394
a:hover {
9495
text-decoration: underline !important;
@@ -125,16 +126,16 @@ text-align: center; -webkit-box-shadow: 0 6px 18px 0 rgba(0, 0, 0, 0.06); -moz-b
125126
<h1 style="color: #1e1e2d; font-weight: 500; margin: 0; font-size: 32px; font-family: 'Rubik', sans-serif;">You have requested to reset your password</h1>
126127
<span style="display: inline-block; vertical-align: middle; margin: 29px 0 26px; border-bottom: 1px solid #cecece; width: 100px;"></span>
127128
<p style="color: #455056; font-size: 15px; line-height: 24px; margin: 0;">
128-
We cannot simply send you your old password. A unique link to reset your password has been generated for you. To reset your password, click the following button and follow the instructions.
129+
${t('cannotSendOldPassword')}
129130
</p>
130131
<a href="${url}" style=" background: #3f51b5; text-decoration: none !important; font-weight: 500; margin-top: 35px; color: #fff;
131132
text-transform: uppercase; font-size: 14px; padding: 10px 24px; display: inline-block; border-radius: 50px; ">
132-
Reset Password
133+
${t('resetPassword')}
133134
</a>
134135
<br/>
135136
<span style="height: 40px;">&nbsp;</span>
136137
<p style="color: #455056; font-size: 15px; line-height: 24px; margin: 0;">
137-
${message} :
138+
${t('passwordResetMessage')} :
138139
<a href="${url}">${url}</a>
139140
</p>
140141
</td>
@@ -175,7 +176,7 @@ const sendMail = async (mailOptions: Mail.Options) => {
175176
const connected = await transporter.verify();
176177

177178
if (!connected) {
178-
throw new Error('Unable to connect to mail server');
179+
throw new Error(t('unableToConnectToMailServer'));
179180
}
180181

181182
// Send mail

0 commit comments

Comments
 (0)