From 498a85b9f2dde5d1a77015e13963207297f3e2b5 Mon Sep 17 00:00:00 2001 From: ariari04 Date: Wed, 28 Aug 2024 11:21:16 +0600 Subject: [PATCH] Add translations --- messages/en.json | 16 +++++++++- messages/kg.json | 16 +++++++++- messages/ru.json | 16 +++++++++- src/app/[locale]/sign-in/reset-code/page.tsx | 9 +++--- src/widgets/forms/ResetCodeForm.tsx | 31 ++++++++------------ src/widgets/forms/SignInForm.tsx | 4 +-- 6 files changed, 64 insertions(+), 28 deletions(-) diff --git a/messages/en.json b/messages/en.json index 5111cf0..7ef2725 100644 --- a/messages/en.json +++ b/messages/en.json @@ -82,7 +82,9 @@ "loginBtn": "Login", "loginGoogle": "Login with Google", "noAccount": "Don't have an account yet?", - "register": "Register" + "register": "Register", + "emailFormat": "Invalid email format", + "passwordMin": "Password must be at least 8 characters long" }, "forgotPasswordEmail": { "enter": "Enter email", @@ -104,5 +106,17 @@ "incorrect": "Incorrect code", "serverError": "Error on the server side", "errorOccured": "An unexpected error occurred" + }, + "resetCode": { + "enterPassword": "Enter new password", + "passInfo": "Password must contain at least 8 characters, 1 capital letter and a number", + "enterPass": "Enter password", + "repeatPassword": "Repeat password", + "repeatPass": "Repeat new password", + "save": "Save", + "noMatch": "Passwords do not match", + "serverError": "Error on the server side", + "noPassword": "Weak password, please avoid obvious passwords", + "errorOccured": "An unexpected error occurred" } } diff --git a/messages/kg.json b/messages/kg.json index b90e38b..f5a2087 100644 --- a/messages/kg.json +++ b/messages/kg.json @@ -82,7 +82,9 @@ "loginBtn": "Кирүү", "loginGoogle": "Google аркылуу кируңуз", "noAccount": "Аккаунт жок?", - "register": "Каттоо" + "register": "Каттоо", + "emailFormat": "Электрондук почта форматы жараксыз", + "passwordMin": "Сырсөз кеминде 8 белгиден турушу керек" }, "forgotPasswordEmail": { "enter": "Электрондук почтаны киргизиңиз", @@ -104,5 +106,17 @@ "incorrect": "Код туура эмес", "serverError": "Сервер тараптагы ката", "errorOccured": "Күтүлбөгөн ката кетти" + }, + "resetCode": { + "enterPassword": "Жаңы сырсөздү киргизиңиз", + "passInfo": "Сырсөз кеминде 8 белгиден, 1 баш тамгадан жана сандан турушу керек", + "enterPass": "Сырсөздү киргизиңиз", + "repeatPassword": "Паролду кайталоо", + "repeatPass": "Жаңы сырсөздү кайталоо", + "save": "Сактоо", + "noMatch": "Сырсөздөр дал келбейт", + "serverError": "Сервер тараптагы ката", + "noPassword": "Начар сырсөз, ачык сырсөздөрдү колдонбоңуз", + "errorOccured": "Күтүлбөгөн ката кетти" } } diff --git a/messages/ru.json b/messages/ru.json index b498744..4235b19 100644 --- a/messages/ru.json +++ b/messages/ru.json @@ -73,7 +73,9 @@ "loginBtn": "Войти", "loginGoogle": "Войти через Google", "noAccount": "Еще нет аккаунта?", - "register": "Зарегистрируйтесь" + "register": "Зарегистрируйтесь", + "emailFormat": "Неверный формат email", + "passwordMin": "Пароль должен содержать минимум 8 символов" }, "forgotPasswordEmail": { "enter": "Введите email", @@ -95,5 +97,17 @@ "incorrect": "Неверный код", "serverError": "Ошибка на стороне сервера", "errorOccured": "Произошла непредвиденная ошибка" + }, + "resetCode": { + "enterPassword": "Введите новый пароль", + "passInfo": "Пароль должен содерждать минимум 8 символов, 1 заглавная буква и цифра", + "enterPass": "Введите пароль", + "repeatPassword": "Повторите пароль", + "repeatPass": "Повторите новый пароль", + "save": "Сохранить", + "noMatch": "Пароли не совпадают", + "serverError": "Ошибка на стороне сервера", + "noPassword": "Слабый пароль, прошу избегайте очевидных паролей", + "errorOccured": "Произошла непредвиденная ошибка" } } diff --git a/src/app/[locale]/sign-in/reset-code/page.tsx b/src/app/[locale]/sign-in/reset-code/page.tsx index 4e48aab..2853ff1 100644 --- a/src/app/[locale]/sign-in/reset-code/page.tsx +++ b/src/app/[locale]/sign-in/reset-code/page.tsx @@ -1,8 +1,10 @@ import Image from "next/image"; import key from "./icons/key.svg"; import ResetCodeForm from "@/widgets/forms/ResetCodeForm"; +import { useTranslations } from "next-intl"; const ResetCode = () => { + const t = useTranslations("resetCode"); return (
@@ -12,12 +14,9 @@ const ResetCode = () => {

- Введите новый пароль + {t("enterPassword")}

-

- Пароль должен содерждать минимум 8 символов, 1 заглавная буква и - цифра -

+

{t("passInfo")}

diff --git a/src/widgets/forms/ResetCodeForm.tsx b/src/widgets/forms/ResetCodeForm.tsx index df2b86d..224e5d1 100644 --- a/src/widgets/forms/ResetCodeForm.tsx +++ b/src/widgets/forms/ResetCodeForm.tsx @@ -14,11 +14,10 @@ import Image from "next/image"; import eye_off from "./icons/eye-off.svg"; import eye_on from "./icons/eye-on.svg"; import alert from "./icons/alert-circle.svg"; +import { useTranslations } from "next-intl"; const ResetCodeForm = () => { - const [passwordWarning, setPasswordWarning] = useState(""); - const [passwordConfirmWarning, setPasswordConfirmWarning] = - useState(""); + const t = useTranslations("resetCode"); const [error, setError] = useState(""); const [loader, setLoader] = useState(false); const [showPasswordOne, setShowPasswordOne] = useState(false); @@ -28,15 +27,11 @@ const ResetCodeForm = () => { const resetCodeFormScheme = z .object({ - new_password1: z - .string() - .min(8, "Пароль должен содержать минимум 8 символов"), - new_password2: z - .string() - .min(8, "Пароль должен содержать минимум 8 символов"), + new_password1: z.string().min(8, t("passInfo")), + new_password2: z.string().min(8, t("passInfo")), }) .refine((data) => data.new_password1 === data.new_password2, { - message: "Пароли не совпадают", + message: t("noMatch"), path: ["new_password2"], }); type FormFields = z.infer; @@ -81,12 +76,12 @@ const ResetCodeForm = () => { if ( [500, 501, 502, 503, 504].includes(error.response?.status as number) ) { - setError("Ошибка на стороне сервера"); + setError(t("serverError")); } else if ([400, 404].includes(error.response?.status as number)) { - setError("Слабый пароль, прошу избегайте очевидных паролей"); + setError(t("noPassword")); } } else { - setError("Произошла непредвиденная ошибка"); + setError(t("errorOccured")); } } finally { setLoader(false); @@ -98,7 +93,7 @@ const ResetCodeForm = () => {
{ }`} > {
{ }`} > { className="mt-8 h-[44px] w-full rounded-md shadow-sm bg-light-blue font-bold leading-6 text-white" type="submit" > - {loader ? : "Сохранить"} + {loader ? : t("save")} ); diff --git a/src/widgets/forms/SignInForm.tsx b/src/widgets/forms/SignInForm.tsx index bd6b365..1d2e7ce 100644 --- a/src/widgets/forms/SignInForm.tsx +++ b/src/widgets/forms/SignInForm.tsx @@ -21,8 +21,8 @@ const SignInForm = ({}) => { const [error, setError] = React.useState(""); const signInFormScheme = z.object({ - email: z.string().email("Неверный формат email"), - password: z.string().min(8, "Пароль должен содержать минимум 8 символов"), + email: z.string().email(t("emailFormat")), + password: z.string().min(8, t("passwordMin")), }); type FormFields = z.infer;