From 8d3649da9deaba8f267d3f16f0cbda40d41d6f30 Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Tue, 11 Jun 2024 15:51:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9B=BD=E9=99=85=E5=8C=96=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=AF=86=E7=A0=81=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/locales/en/account.json | 12 +++++++++++ public/locales/zh/account.json | 12 +++++++++++ public/locales/zh/common.json | 4 ---- src/i18n/index.js | 2 +- src/views/account/ChangePassword.jsx | 31 ++++++++++++++-------------- 5 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 public/locales/en/account.json create mode 100644 public/locales/zh/account.json diff --git a/public/locales/en/account.json b/public/locales/en/account.json new file mode 100644 index 0000000..7abb5cf --- /dev/null +++ b/public/locales/en/account.json @@ -0,0 +1,12 @@ +{ + "CurrentPassword": "Current password", + "NewPassword": "New password", + "ReenterPassword": "Reenter password", + "Validation": { + "Success": "Your password has been successfully updated.", + "Fail": "Failed to change password. Please try again.", + "CurrentPassword": "Please input your password.", + "NewPassword": "Please input your new password.", + "ReenterPassword": "Please reenter your password." + } +} \ No newline at end of file diff --git a/public/locales/zh/account.json b/public/locales/zh/account.json new file mode 100644 index 0000000..a7caf37 --- /dev/null +++ b/public/locales/zh/account.json @@ -0,0 +1,12 @@ +{ + "CurrentPassword": "当前密码", + "NewPassword": "新密码", + "ReenterPassword": "重复输入密码", + "Validation": { + "Success": "密码更新成功", + "Fail": "密码更新失败", + "CurrentPassword": "请输入密码。", + "NewPassword": "请输入新密码。", + "ReenterPassword": "请重复输入密码。" + } +} \ No newline at end of file diff --git a/public/locales/zh/common.json b/public/locales/zh/common.json index d1f3789..7511da4 100644 --- a/public/locales/zh/common.json +++ b/public/locales/zh/common.json @@ -51,10 +51,6 @@ "Notice": "通知", "Report": "质量评分" }, - "Notification": { - "Title": "温馨提示", - "LoginFailed": "密码错误,登陆失败。" - }, "Validation": { "Title": "温馨提示", "LoginFailed": "密码错误,登陆失败。", diff --git a/src/i18n/index.js b/src/i18n/index.js index b787ea2..9efd3bd 100644 --- a/src/i18n/index.js +++ b/src/i18n/index.js @@ -17,7 +17,7 @@ i18n backend: { loadPath: '/locales/{{lng}}/{{ns}}.json', }, - ns: ['common', 'group', 'vendor'], + ns: ['common', 'group', 'vendor', 'account'], defaultNS: 'common', detection: { // convertDetectedLanguage: 'Iso15897', diff --git a/src/views/account/ChangePassword.jsx b/src/views/account/ChangePassword.jsx index 1cf1eb1..11e63e5 100644 --- a/src/views/account/ChangePassword.jsx +++ b/src/views/account/ChangePassword.jsx @@ -1,14 +1,15 @@ import { useNavigate } from "react-router-dom" import { Button, Space, Form, Input, Row, Typography, App } from 'antd' +import { useTranslation } from 'react-i18next' import useAuthStore from '@/stores/Auth' const { Title } = Typography function ChangePassword() { + const { t } = useTranslation() const navigate = useNavigate() - const [changeUserPassword] = useAuthStore( - (state) => [state.changeUserPassword]) + const changeUserPassword = useAuthStore((state) => state.changeUserPassword) const { notification } = App.useApp() const [form] = Form.useForm() @@ -16,8 +17,8 @@ function ChangePassword() { changeUserPassword(values.currentPassword, values.newPassword) .then(() => { notification.success({ - message: `Notification`, - description: 'Your password has been successfully updated.', + message: t('Validation.Title'), + description: t('account:Validation.Success'), placement: 'top', duration: 4, }) @@ -25,8 +26,8 @@ function ChangePassword() { }) .catch(() => { notification.error({ - message: `Notification`, - description: 'Failed to change password. Please try again.', + message: t('Validation.Title'), + description: t('account:Validation.Fail'), placement: 'top', duration: 4, }) @@ -53,38 +54,38 @@ function ChangePassword() { onFinishFailed={onFinishFailed} autoComplete="off" > - Change your password + {t('ChangePassword')} @@ -93,10 +94,10 @@ function ChangePassword() {