This commit is contained in:
hailin 2025-04-18 17:53:30 +08:00
parent 1df7f447cd
commit b05084f939
5 changed files with 58 additions and 10 deletions

View File

@ -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

View File

@ -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<ProfileStepProps> = ({
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<ProfileStepProps> = ({
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<ProfileStepProps> = ({
<>
<div className="space-y-1">
<div className="flex items-center space-x-2">
<Label>Username</Label>
<Label>{t("login.username")}</Label>
<div className="text-xs">
{usernameAvailable ? (
<div className="text-green-500">AVAILABLE</div>
<div className="text-green-500">{t("login.available")}</div>
) : (
<div className="text-red-500">UNAVAILABLE</div>
<div className="text-red-500">{t("login.unavailable")}</div>
)}
</div>
</div>
@ -105,7 +110,7 @@ export const ProfileStep: FC<ProfileStepProps> = ({
<div className="relative">
<Input
className="pr-10"
placeholder="username"
placeholder={t("login.usernamePlaceholder")}
value={username}
onChange={e => {
onUsernameChange(e.target.value)
@ -130,10 +135,10 @@ export const ProfileStep: FC<ProfileStepProps> = ({
</div>
<div className="space-y-1">
<Label>Chat Display Name</Label>
<Label>{t("login.chatDisplayName")}</Label>
<Input
placeholder="Your Name"
placeholder={t("login.displayNamePlaceholder")}
value={displayName}
onChange={e => onDisplayNameChange(e.target.value)}
maxLength={PROFILE_DISPLAY_NAME_MAX}

View File

@ -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"
}
}

View File

@ -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": "あなたの名前"
}
}

View File

@ -22,6 +22,13 @@
"reset": "重置",
"emailNotAllowed": "邮箱 {{email}} 不允许注册。",
"passwordResetMessage": "请检查邮箱以重置密码",
"errorUnexpected": "发生了意外错误"
"errorUnexpected": "发生了意外错误",
"username": "用户名",
"usernamePlaceholder": "请输入用户名",
"available": "可用",
"unavailable": "不可用",
"usernameError": "用户名只能包含字母、数字或下划线,不能包含其他字符或空格。",
"chatDisplayName": "聊天显示名称",
"displayNamePlaceholder": "您的名称"
}
}