From b05084f9392150c670fea7e46bb3ed0c90ed770f Mon Sep 17 00:00:00 2001 From: hailin Date: Fri, 18 Apr 2025 17:53:30 +0800 Subject: [PATCH] . --- app/[locale]/setup/page.tsx | 10 +++++++++- components/setup/profile-step.tsx | 19 ++++++++++++------- public/locales/en/translation.json | 9 ++++++++- public/locales/ja/translation.json | 21 +++++++++++++++++++++ public/locales/zh/translation.json | 9 ++++++++- 5 files changed, 58 insertions(+), 10 deletions(-) diff --git a/app/[locale]/setup/page.tsx b/app/[locale]/setup/page.tsx index 94d7fa1..371ac43 100644 --- a/app/[locale]/setup/page.tsx +++ b/app/[locale]/setup/page.tsx @@ -23,6 +23,8 @@ import { } from "../../../components/setup/step-container" import { useTranslation } from 'react-i18next' +import { usePathname } from "next/navigation" + export default function SetupPage() { const { profile, @@ -35,6 +37,7 @@ export default function SetupPage() { } = useContext(ChatbotUIContext) const router = useRouter() + const pathname = usePathname() // 获取当前路径 const { t } = useTranslation() @@ -69,7 +72,12 @@ export default function SetupPage() { const session = (await supabase.auth.getSession()).data.session if (!session) { - return router.push("/login") + + // 提取当前路径中的 locale 部分 + const locale = pathname.split("/")[1] || "en" // 获取路径中的 locale 部分,如果没有则默认为 "en" + + // 强制跳转到带有 locale 的 login 页面 + return router.push("/${locale}/login") } else { const user = session.user diff --git a/components/setup/profile-step.tsx b/components/setup/profile-step.tsx index eaf8faf..99f273e 100644 --- a/components/setup/profile-step.tsx +++ b/components/setup/profile-step.tsx @@ -1,3 +1,5 @@ +import { useTranslation } from "react-i18next" // 导入 useTranslation + import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { @@ -31,6 +33,8 @@ export const ProfileStep: FC = ({ onUsernameChange, onDisplayNameChange }) => { + const { t } = useTranslation() // 使用 t 函数来获取翻译内容 + const [loading, setLoading] = useState(false) const debounce = (func: (...args: any[]) => void, wait: number) => { @@ -65,7 +69,8 @@ export const ProfileStep: FC = ({ if (!usernameRegex.test(username)) { onUsernameAvailableChange(false) toast.error( - "Username must be letters, numbers, or underscores only - no other characters or spacing allowed." + t("login.usernameError") + //"Username must be letters, numbers, or underscores only - no other characters or spacing allowed." ) return } @@ -91,13 +96,13 @@ export const ProfileStep: FC = ({ <>
- +
{usernameAvailable ? ( -
AVAILABLE
+
{t("login.available")}
) : ( -
UNAVAILABLE
+
{t("login.unavailable")}
)}
@@ -105,7 +110,7 @@ export const ProfileStep: FC = ({
{ onUsernameChange(e.target.value) @@ -130,10 +135,10 @@ export const ProfileStep: FC = ({
- + onDisplayNameChange(e.target.value)} maxLength={PROFILE_DISPLAY_NAME_MAX} diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index a1ee78a..ef6f18f 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -23,6 +23,13 @@ "reset": "Reset", "emailNotAllowed": "Email {{email}} is not allowed to sign up.", "passwordResetMessage": "Check email to reset password", - "errorUnexpected": "An unexpected error occurred" + "errorUnexpected": "An unexpected error occurred", + "username": "Username", + "usernamePlaceholder": "Enter username", + "available": "AVAILABLE", + "unavailable": "UNAVAILABLE", + "usernameError": "Username must be letters, numbers, or underscores only - no other characters or spacing allowed.", + "chatDisplayName": "Chat Display Name", + "displayNamePlaceholder": "Your Name" } } diff --git a/public/locales/ja/translation.json b/public/locales/ja/translation.json index 1af1f02..772091a 100644 --- a/public/locales/ja/translation.json +++ b/public/locales/ja/translation.json @@ -9,6 +9,27 @@ "SetAPIKeysOptional": "APIキーの設定(オプション)", "YouAreAllSetUp": "設定が完了しました!", "SetupComplete": "セットアップ完了" + }, + + "login": { + "email": "メールアドレス", + "emailPlaceholder": "you@example.com", + "password": "パスワード", + "passwordPlaceholder": "••••••••", + "loginButton": "ログイン", + "signUpButton": "サインアップ", + "forgotPassword": "パスワードを忘れましたか?", + "reset": "リセット", + "emailNotAllowed": "メールアドレス {{email}} は登録できません。", + "passwordResetMessage": "パスワードリセットのためにメールを確認してください。", + "errorUnexpected": "予期しないエラーが発生しました", + "username": "ユーザー名", + "usernamePlaceholder": "ユーザー名を入力してください", + "available": "利用可能", + "unavailable": "利用不可", + "usernameError": "ユーザー名は文字、数字、またはアンダースコアのみで、その他の文字やスペースは使用できません。", + "chatDisplayName": "チャット表示名", + "displayNamePlaceholder": "あなたの名前" } } \ No newline at end of file diff --git a/public/locales/zh/translation.json b/public/locales/zh/translation.json index bc2e345..180466a 100644 --- a/public/locales/zh/translation.json +++ b/public/locales/zh/translation.json @@ -22,6 +22,13 @@ "reset": "重置", "emailNotAllowed": "邮箱 {{email}} 不允许注册。", "passwordResetMessage": "请检查邮箱以重置密码", - "errorUnexpected": "发生了意外错误" + "errorUnexpected": "发生了意外错误", + "username": "用户名", + "usernamePlaceholder": "请输入用户名", + "available": "可用", + "unavailable": "不可用", + "usernameError": "用户名只能包含字母、数字或下划线,不能包含其他字符或空格。", + "chatDisplayName": "聊天显示名称", + "displayNamePlaceholder": "您的名称" } }