Skip to content

Commit

Permalink
Customize accept-language header to pass locale info (#932)
Browse files Browse the repository at this point in the history
* Customize accept-language header to pass locale info

* Update the accept language to standard language
  • Loading branch information
hiveer authored Feb 10, 2025
1 parent b74b64a commit 5181fe2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion frontend/src/packs/useFetchApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ const popupReloginDialog = () => {
})
}

const acceptLanguage = () => {
const currentLocale = cookies.get('locale')
if (currentLocale === 'en') {
return 'en-US'
} else if (currentLocale === 'zh') {
return 'zh-CN'
} else {
return 'en-US'
}
}

const useFetchApi = createFetch({
updateDataOnError: true,
baseUrl: `${CSGHUB_SERVER}/api/v1`,
Expand All @@ -38,7 +49,8 @@ const useFetchApi = createFetch({
const jwtToken = cookies.get('user_token')
options.headers = {
...options.headers,
Authorization: `Bearer ${jwtToken}`
Authorization: `Bearer ${jwtToken}`,
'Accept-Language': acceptLanguage()
}
}
return { options }
Expand Down

0 comments on commit 5181fe2

Please sign in to comment.