feat: 添加前后端多语言支持

前端:
- 在 API 请求中添加 Accept-Language 头,传递当前语言设置

后端:
- 创建 LanguageMiddleware 中间件,自动检测并设置语言
- 为所有 API 路由添加语言中间件

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-02-25 18:21:05 +08:00
parent 8817effc9a
commit eef91a6c83
3 changed files with 43 additions and 5 deletions
+4 -1
View File
@@ -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) => {