From 0163e950079377a8e4bd6c393c77567fbf9d2df4 Mon Sep 17 00:00:00 2001 From: hailin Date: Thu, 22 May 2025 19:49:33 +0800 Subject: [PATCH] . --- chatdesk-ui/app/[locale]/login/page.tsx | 6 +-- .../components/ui/language-switcher.tsx | 41 +------------------ .../components/utility/home-redirector.tsx | 2 +- 3 files changed, 4 insertions(+), 45 deletions(-) diff --git a/chatdesk-ui/app/[locale]/login/page.tsx b/chatdesk-ui/app/[locale]/login/page.tsx index 59f5de9..a18f7c0 100644 --- a/chatdesk-ui/app/[locale]/login/page.tsx +++ b/chatdesk-ui/app/[locale]/login/page.tsx @@ -71,10 +71,8 @@ export default async function Login({ console.error("Host URL is not available"); } - // 延时 2 秒后再跳转到根目录 - setTimeout(() => { - return redirect(`/${localeString}`); - }, 2000); + return redirect(`/${localeString}`); + //return redirect(`/${localeString}/login`); } diff --git a/chatdesk-ui/components/ui/language-switcher.tsx b/chatdesk-ui/components/ui/language-switcher.tsx index adca72a..5ab6a5c 100644 --- a/chatdesk-ui/components/ui/language-switcher.tsx +++ b/chatdesk-ui/components/ui/language-switcher.tsx @@ -22,8 +22,6 @@ export function LanguageSwitcher() { if (typeof window !== 'undefined') { const saved = localStorage.getItem('preferred-language') - // console.log('[LanguageSwitcher]=> Read from localstorage preferred-language=', saved) - const isLocaleInPath = i18nConfig.locales.includes(currentLocale as any) } @@ -32,43 +30,6 @@ export function LanguageSwitcher() { } }, [currentLocale]) - // const handleChange = (e: React.ChangeEvent) => { - // const newLocale = e.target.value - // // 仅在用户选择语言后保存 cookie - // // console.log('[LanguageSwitcher] Write Cookie newLocale value:', newLocale) - // // document.cookie = `preferred-language=${newLocale}; path=/; max-age=31536000` - - // // 同时更新 localStorage - // localStorage.setItem('preferred-language', newLocale) - - // // 验证 cookie 是否成功写入 - // // const cookieValue = document.cookie - - // // 更新 i18n 的语言 - // i18n.changeLanguage(newLocale) // 修改 TranslationProvider 中的 locale - - // let segments = pathname === '/' ? [] : pathname.split('/').filter(Boolean) - // const isLocaleInPath = i18nConfig.locales.includes(segments[0] as any) - - // if (isLocaleInPath) { - // segments[0] = newLocale - // } else { - // segments.unshift(newLocale) - // } - - // const newPath = '/' + segments.join('/') - - // // 延迟跳转,确保 cookie 写入完成 - // setTimeout(() => { - // startTransition(() => { - // if (pathname !== newPath) { - // router.push(newPath) - // } else { - // router.refresh() - // } - // }) - // }, 0) - // } const handleChange = (e: React.ChangeEvent) => { const newLocale = e.target.value @@ -77,7 +38,7 @@ export function LanguageSwitcher() { localStorage.setItem('preferred-language', newLocale) // 更新 i18n 的语言 - i18n.changeLanguage(newLocale) + //i18n.changeLanguage(newLocale) let segments = pathname === '/' ? [] : pathname.split('/').filter(Boolean) const isLocaleInPath = i18nConfig.locales.includes(segments[0] as any) diff --git a/chatdesk-ui/components/utility/home-redirector.tsx b/chatdesk-ui/components/utility/home-redirector.tsx index 2fcb3fe..6741edd 100644 --- a/chatdesk-ui/components/utility/home-redirector.tsx +++ b/chatdesk-ui/components/utility/home-redirector.tsx @@ -27,7 +27,7 @@ export default function HomeRedirector() { //document.cookie = `preferred-language=${preferred}; path=/; max-age=31536000` // 1 年 // 修改 i18n 中的语言 - i18n.changeLanguage(preferred) // 更新 i18n 的 locale + //i18n.changeLanguage(preferred) // 更新 i18n 的 locale const pathLocale = currentPath.split('/')[1] const hasLocaleInPath = isValidLocale(pathLocale)