From 5181fe24eb47db5666fa09cd89f986e09e31cb2d Mon Sep 17 00:00:00 2001 From: Hiveer Date: Mon, 10 Feb 2025 18:26:34 +0800 Subject: [PATCH] Customize accept-language header to pass locale info (#932) * Customize accept-language header to pass locale info * Update the accept language to standard language --- frontend/src/packs/useFetchApi.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend/src/packs/useFetchApi.js b/frontend/src/packs/useFetchApi.js index 9fae7c656..7ef11e169 100644 --- a/frontend/src/packs/useFetchApi.js +++ b/frontend/src/packs/useFetchApi.js @@ -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`, @@ -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 }