This commit is contained in:
hailin 2025-04-17 18:46:49 +08:00
parent 3489ba4f93
commit 2d16d4b895
1 changed files with 3 additions and 2 deletions

View File

@ -34,11 +34,12 @@ export function LanguageSwitcher() {
const handleChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
const newLocale = e.target.value
// 仅在用户选择语言后保存 cookie
console.log('[LanguageSwitcher] Write Cookie newLocale value:', newLocale)
document.cookie = `preferred-language=${newLocale}; path=/; max-age=31536000`
// 验证 cookie 是否成功写入
const cookieValue = document.cookie
console.log('[LanguageSwitcher] Cookie set to:', cookieValue)
console.log('[LanguageSwitcher] Check writed Cookie value:', cookieValue)
let segments = pathname === '/' ? [] : pathname.split('/').filter(Boolean)
const isLocaleInPath = i18nConfig.locales.includes(segments[0] as any)