fix: 修复前端语言切换时后端 header 未更新的问题
- 统一 localStorage key:LanguageSwitcher 同时保存到 i18n_language 和 i18nextLng - 优化 API 请求拦截器:添加 getCurrentLanguage() 函数,优先从 localStorage 读取最新语言设置 - 支持兼容性:同时读取 i18n_language 和 i18nextLng(i18next 默认 key) - 规范化语言格式:确保返回正确的语言代码(zh-CN, zh-TW, en)
This commit is contained in:
@@ -22,7 +22,9 @@ const LanguageSwitcher: React.FC = () => {
|
||||
const handleChange = async (value: string) => {
|
||||
setCurrentLang(value)
|
||||
await i18n.changeLanguage(value)
|
||||
// 保存到 localStorage
|
||||
// 保存到 localStorage(统一使用 i18n_language)
|
||||
localStorage.setItem('i18n_language', value)
|
||||
// 同时保存到 i18nextLng(i18next 默认使用的 key,用于兼容)
|
||||
localStorage.setItem('i18nextLng', value)
|
||||
// 刷新页面以应用 Ant Design 的 locale 和所有翻译
|
||||
window.location.reload()
|
||||
|
||||
Reference in New Issue
Block a user