feat: 添加前后端多语言支持
前端: - 在 API 请求中添加 Accept-Language 头,传递当前语言设置 后端: - 创建 LanguageMiddleware 中间件,自动检测并设置语言 - 为所有 API 路由添加语言中间件 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,13 +11,16 @@ const api = axios.create({
|
||||
},
|
||||
})
|
||||
|
||||
// 请求拦截器:添加 token
|
||||
// 请求拦截器:添加 token 和语言
|
||||
api.interceptors.request.use(
|
||||
(config) => {
|
||||
const token = localStorage.getItem('token')
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
// 添加语言头
|
||||
const lang = localStorage.getItem('i18nextLng') || 'zh'
|
||||
config.headers['Accept-Language'] = lang
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
|
||||
Reference in New Issue
Block a user