Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix(user-interface): fix how to get current lang

haitao(lj)3f04532003f1
diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.ts
index a4c7dcd2..1e61d874 100644
--- a/ui/src/common/interface.ts
+++ b/ui/src/common/interface.ts
@@ -116,9 +116,12 @@ export interface UserInfoRes extends UserInfoBase {
bio: string;
bio_html: string;
create_time?: string;
- /** value = 1 active; value = 2 inactivated
+ /**
+ * value = 1 active;
+ * value = 2 inactivated
*/
mail_status: number;
+ language: string;
e_mail?: string;
[prop: string]: any;
}
diff --git a/ui/src/pages/Users/Settings/Interface/index.tsx b/ui/src/pages/Users/Settings/Interface/index.tsx
index c39bf0b9..fb78f608 100644
--- a/ui/src/pages/Users/Settings/Interface/index.tsx
+++ b/ui/src/pages/Users/Settings/Interface/index.tsx
@@ -5,8 +5,6 @@ import { useTranslation } from 'react-i18next';
import type { LangsType, FormDataType } from '@/common/interface';
import { useToast } from '@/hooks';
import { getLanguageOptions, updateUserInterface } from '@/services';
-import { CURRENT_LANG_STORAGE_KEY } from '@/common/constants';
-import Storage from '@/utils/storage';
import { localize } from '@/utils';
import { loggedUserInfoStore } from '@/stores';
@@ -19,8 +17,7 @@ const Index = () => {
const [langs, setLangs] = useState<LangsType[]>();
const [formData, setFormData] = useState<FormDataType>({
lang: {
- // FIXME: userinfo? or userInfo.language
- value: loggedUserInfo,
+ value: loggedUserInfo.language,
isInvalid: false,
errorMsg: '',
},
@@ -49,17 +46,6 @@ const Index = () => {
useEffect(() => {
getLangs();
- // TODO: get default lang by interface api
- const lang = Storage.get(CURRENT_LANG_STORAGE_KEY);
- if (lang) {
- setFormData({
- lang: {
- value: lang,
- isInvalid: false,
- errorMsg: '',
- },
- });
- }
}, []);
return (
<Form noValidate onSubmit={handleSubmit}>
diff --git a/ui/src/utils/request.ts b/ui/src/utils/request.ts
index 8167448d..7859b90d 100644
--- a/ui/src/utils/request.ts
+++ b/ui/src/utils/request.ts
@@ -3,12 +3,9 @@ import type { AxiosInstance, AxiosRequestConfig, AxiosError } from 'axios';
import { Modal } from '@/components';
import { loggedUserInfoStore, toastStore } from '@/stores';
-import {
- LOGGED_TOKEN_STORAGE_KEY,
- CURRENT_LANG_STORAGE_KEY,
- DEFAULT_LANG,
-} from '@/common/constants';
+import { LOGGED_TOKEN_STORAGE_KEY } from '@/common/constants';
import { RouteAlias } from '@/router/alias';
+import { getCurrentLang } from '@/utils/localize';
import Storage from './storage';
import { floppyNavigation } from './floppyNavigation';
@@ -35,8 +32,7 @@ class Request {
this.instance.interceptors.request.use(
(requestConfig: AxiosRequestConfig) => {
const token = Storage.get(LOGGED_TOKEN_STORAGE_KEY) || '';
- // default lang en_US
- const lang = Storage.get(CURRENT_LANG_STORAGE_KEY) || DEFAULT_LANG;
+ const lang = getCurrentLang();
requestConfig.headers = {
Authorization: token,
'Accept-Language': lang,