This commit is contained in:
hailin 2025-04-17 13:56:23 +08:00
parent 6d3eaf1f33
commit 92adad6b80
1 changed files with 3 additions and 6 deletions

View File

@ -21,23 +21,20 @@ export function LanguageSwitcher() {
if (!isLocaleInPath && saved !== currentLocale) {
localStorage.setItem('preferred-language', currentLocale)
document.cookie = `preferred-language=${currentLocale}; path=/; max-age=31536000`
console.log('[LanguageSwitcher] set preferred-language to:', currentLocale)
// 确保 cookie 写入
// 验证 cookie 是否成功写入
const cookieValue = document.cookie
console.log('[LanguageSwitcher] Cookie after setting:', cookieValue)
console.log('[LanguageSwitcher] Current cookies:', cookieValue)
}
}
}, [currentLocale])
const handleChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
const newLocale = e.target.value
// 写入 cookie
document.cookie = `preferred-language=${newLocale}; path=/; max-age=31536000`
// 检查 cookie 是否正确写入
// 验证 cookie 是否成功写入
const cookieValue = document.cookie
console.log('[LanguageSwitcher] Cookie set to:', cookieValue)