From 1afc064d7a766a27886cc41005dd81bfdf871a76 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sat, 30 Apr 2022 16:49:14 +0800 Subject: [PATCH] i18n: captcha --- public/locales/en-US/application.json | 1 + public/locales/en-US/common.json | 4 +++- public/locales/zh-CN/application.json | 1 + public/locales/zh-CN/common.json | 4 +++- src/hooks/normal.js | 6 ++++-- src/middleware/Api.ts | 2 +- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/public/locales/en-US/application.json b/public/locales/en-US/application.json index 1081e50..236e5a3 100644 --- a/public/locales/en-US/application.json +++ b/public/locales/en-US/application.json @@ -3,6 +3,7 @@ "email": "Email", "password": "Password", "captcha": "CAPTCHA", + "captchaError": "Cannot load CAPTCHA: {{message}}", "signIn": "Sign in", "signUp": "Sign up", "signUpAccount": "Sign up", diff --git a/public/locales/en-US/common.json b/public/locales/en-US/common.json index b6e6d7a..578441e 100644 --- a/public/locales/en-US/common.json +++ b/public/locales/en-US/common.json @@ -13,6 +13,8 @@ "40001": "Wrong format of input parameters ({{message}})", "40021": "User not found", "40022": "Verification code not correct", - "40023": "Login session not exist" + "40023": "Login session not exist", + "40024": "Cannot initialize WebAuthn", + "40025": "Authentication failed" } } \ No newline at end of file diff --git a/public/locales/zh-CN/application.json b/public/locales/zh-CN/application.json index 2b49274..dd57017 100644 --- a/public/locales/zh-CN/application.json +++ b/public/locales/zh-CN/application.json @@ -3,6 +3,7 @@ "email": "电子邮箱", "password": "密码", "captcha": "验证码", + "captchaError": "Cannot load CAPTCHA: {{message}}", "signIn": "登录", "signUp": "注册", "signUpAccount": "注册账号", diff --git a/public/locales/zh-CN/common.json b/public/locales/zh-CN/common.json index b2df006..572d5d3 100644 --- a/public/locales/zh-CN/common.json +++ b/public/locales/zh-CN/common.json @@ -13,6 +13,8 @@ "40001": "输入参数格式有误 ({{message}})", "40021": "用户不存在", "40022": "验证代码不正确", - "40023": "登录会话不存在" + "40023": "登录会话不存在", + "40024": "无法初始化 WebAuthn", + "40025": "验证失败" } } \ No newline at end of file diff --git a/src/hooks/normal.js b/src/hooks/normal.js index bfebcf3..f405bc1 100644 --- a/src/hooks/normal.js +++ b/src/hooks/normal.js @@ -11,11 +11,13 @@ import { FormControl, Input, InputLabel } from "@material-ui/core"; import Placeholder from "../component/Placeholder/Captcha"; import { defaultValidate, useStyle } from "./useCaptcha"; import { toggleSnackbar } from "../redux/explorer"; +import { useTranslation } from "react-i18next"; const NormalCaptcha = forwardRef(function NormalCaptcha( { captchaRef, setLoading }, ref ) { + const { t } = useTranslation(); const classes = useStyle(); const [captcha, setCaptcha] = useState(""); @@ -38,7 +40,7 @@ const NormalCaptcha = forwardRef(function NormalCaptcha( ToggleSnackbar( "top", "right", - "无法加载验证码:" + error.message, + t("login.captchaError", { message: error.message }), "error" ); }); @@ -56,7 +58,7 @@ const NormalCaptcha = forwardRef(function NormalCaptcha( return (
- 验证码 + {t("login.captcha")} setCaptcha(e.target.value)} diff --git a/src/middleware/Api.ts b/src/middleware/Api.ts index f1daf1c..d0b05f9 100644 --- a/src/middleware/Api.ts +++ b/src/middleware/Api.ts @@ -45,7 +45,7 @@ class AppError extends Error { message || i18next.t("unknownError", { ns: "common" }); } - this.message += error ? " " + error : ""; + this.message += error ? ` (${error})` : ""; this.stack = new Error().stack; } }