balibabu commited on
Commit
5769711
·
1 Parent(s): 85bfa49

Fixed an issue where refreshing the login page caused the language settings to become invalid. #249 (#250)

Browse files

### What problem does this PR solve?

Fixed an issue where refreshing the login page caused the language
settings to become invalid.

Issue link: #249

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

web/src/app.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import i18next from '@/locales/config';
2
  import { App, ConfigProvider, ConfigProviderProps } from 'antd';
3
  import enUS from 'antd/locale/en_US';
4
  import zhCN from 'antd/locale/zh_CN';
@@ -18,8 +18,12 @@ const RootProvider = ({ children }: React.PropsWithChildren) => {
18
  });
19
 
20
  useEffect(() => {
21
- i18next.changeLanguage(storage.getLanguage());
22
- }, [locale]);
 
 
 
 
23
 
24
  return (
25
  <ConfigProvider
 
1
+ import { default as i18n, default as i18next } from '@/locales/config';
2
  import { App, ConfigProvider, ConfigProviderProps } from 'antd';
3
  import enUS from 'antd/locale/en_US';
4
  import zhCN from 'antd/locale/zh_CN';
 
18
  });
19
 
20
  useEffect(() => {
21
+ // Because the language is saved in the backend, a token is required to obtain the api. However, the login page cannot obtain the language through the getUserInfo api, so the language needs to be saved in localstorage.
22
+ const lng = storage.getLanguage();
23
+ if (lng) {
24
+ i18n.changeLanguage(lng);
25
+ }
26
+ }, []);
27
 
28
  return (
29
  <ConfigProvider
web/src/layouts/components/header/index.tsx CHANGED
@@ -1,16 +1,15 @@
1
  import { ReactComponent as StarIon } from '@/assets/svg/chat-star.svg';
2
  import { ReactComponent as KnowledgeBaseIcon } from '@/assets/svg/knowledge-base.svg';
3
  import { ReactComponent as Logo } from '@/assets/svg/logo.svg';
 
 
4
  import { Layout, Radio, Space, theme } from 'antd';
 
 
5
  import Toolbar from '../right-toolbar';
6
 
7
  import styles from './index.less';
8
 
9
- import { useNavigateWithFromState } from '@/hooks/routeHook';
10
- import { useCallback, useMemo } from 'react';
11
- import { useTranslation } from 'react-i18next';
12
- import { useLocation } from 'umi';
13
-
14
  const { Header } = Layout;
15
 
16
  const RagHeader = () => {
@@ -19,7 +18,7 @@ const RagHeader = () => {
19
  } = theme.useToken();
20
  const navigate = useNavigateWithFromState();
21
  const { pathname } = useLocation();
22
- const { t } = useTranslation('translation', { keyPrefix: 'header' });
23
 
24
  const tagsData = useMemo(
25
  () => [
 
1
  import { ReactComponent as StarIon } from '@/assets/svg/chat-star.svg';
2
  import { ReactComponent as KnowledgeBaseIcon } from '@/assets/svg/knowledge-base.svg';
3
  import { ReactComponent as Logo } from '@/assets/svg/logo.svg';
4
+ import { useTranslate } from '@/hooks/commonHooks';
5
+ import { useNavigateWithFromState } from '@/hooks/routeHook';
6
  import { Layout, Radio, Space, theme } from 'antd';
7
+ import { useCallback, useMemo } from 'react';
8
+ import { useLocation } from 'umi';
9
  import Toolbar from '../right-toolbar';
10
 
11
  import styles from './index.less';
12
 
 
 
 
 
 
13
  const { Header } = Layout;
14
 
15
  const RagHeader = () => {
 
18
  } = theme.useToken();
19
  const navigate = useNavigateWithFromState();
20
  const { pathname } = useLocation();
21
+ const { t } = useTranslate('header');
22
 
23
  const tagsData = useMemo(
24
  () => [
web/src/locales/en.ts CHANGED
@@ -129,6 +129,7 @@ export default {
129
  uploadTitle: 'Click or drag file to this area to upload',
130
  uploadDescription:
131
  'Support for a single or bulk upload. Strictly prohibited from uploading company data or other banned files.',
 
132
  },
133
  knowledgeConfiguration: {
134
  titleDescription:
@@ -256,6 +257,7 @@ export default {
256
  chunkMessage: 'Please input value!',
257
  },
258
  chat: {
 
259
  assistantSetting: 'Assistant Setting',
260
  promptEngine: 'Prompt Engine',
261
  modelSetting: 'Model Setting',
@@ -383,7 +385,7 @@ export default {
383
  img2txtModel: 'Img2txt model',
384
  img2txtModelTip:
385
  'The default multi-module model all the newly created knowledgebase will use. It can describe a picture or video.',
386
- sequence2txtModel: 'Img2txt model',
387
  sequence2txtModelTip:
388
  'The default ASR model all the newly created knowledgebase will use. Use this model to translate voices to corresponding text.',
389
  workspace: 'Workspace',
 
129
  uploadTitle: 'Click or drag file to this area to upload',
130
  uploadDescription:
131
  'Support for a single or bulk upload. Strictly prohibited from uploading company data or other banned files.',
132
+ chunk: 'Chunk',
133
  },
134
  knowledgeConfiguration: {
135
  titleDescription:
 
257
  chunkMessage: 'Please input value!',
258
  },
259
  chat: {
260
+ createAssistant: 'Create an Assistant',
261
  assistantSetting: 'Assistant Setting',
262
  promptEngine: 'Prompt Engine',
263
  modelSetting: 'Model Setting',
 
385
  img2txtModel: 'Img2txt model',
386
  img2txtModelTip:
387
  'The default multi-module model all the newly created knowledgebase will use. It can describe a picture or video.',
388
+ sequence2txtModel: 'Sequence2txt model',
389
  sequence2txtModelTip:
390
  'The default ASR model all the newly created knowledgebase will use. Use this model to translate voices to corresponding text.',
391
  workspace: 'Workspace',
web/src/locales/zh.ts CHANGED
@@ -71,7 +71,7 @@ export default {
71
  searchFiles: '搜索文件',
72
  localFiles: '本地文件',
73
  emptyFiles: '新建空文件',
74
- chunkNumber: '模块数',
75
  uploadDate: '上传日期',
76
  chunkMethod: '解析方法',
77
  enabled: '启用',
@@ -94,7 +94,7 @@ export default {
94
  testTextPlaceholder: '请输入您的问题!',
95
  testingLabel: '测试',
96
  similarity: '混合相似度',
97
- termSimilarity: '术语相似度',
98
  vectorSimilarity: '向量相似度',
99
  hits: '命中数',
100
  view: '看法',
@@ -126,6 +126,7 @@ export default {
126
  uploadTitle: '点击或拖拽文件至此区域即可上传',
127
  uploadDescription:
128
  '支持单次或批量上传。 严禁上传公司数据或其他违禁文件。',
 
129
  },
130
  knowledgeConfiguration: {
131
  titleDescription: '在这里更新您的知识库详细信息,尤其是解析方法。',
@@ -248,6 +249,7 @@ export default {
248
  chunkMessage: '请输入值!',
249
  },
250
  chat: {
 
251
  assistantSetting: '助理设置',
252
  promptEngine: '提示引擎',
253
  modelSetting: '模型设置',
@@ -368,7 +370,7 @@ export default {
368
  img2txtModel: 'Img2txt模型',
369
  img2txtModelTip:
370
  '所有新创建的知识库都将使用默认的多模块模型。 它可以描述图片或视频。',
371
- sequence2txtModel: 'Img2txt模型',
372
  sequence2txtModelTip:
373
  '所有新创建的知识库都将使用默认的 ASR 模型。 使用此模型将语音翻译为相应的文本。',
374
  workspace: '工作空间',
 
71
  searchFiles: '搜索文件',
72
  localFiles: '本地文件',
73
  emptyFiles: '新建空文件',
74
+ chunkNumber: '分块数',
75
  uploadDate: '上传日期',
76
  chunkMethod: '解析方法',
77
  enabled: '启用',
 
94
  testTextPlaceholder: '请输入您的问题!',
95
  testingLabel: '测试',
96
  similarity: '混合相似度',
97
+ termSimilarity: '关键词相似度',
98
  vectorSimilarity: '向量相似度',
99
  hits: '命中数',
100
  view: '看法',
 
126
  uploadTitle: '点击或拖拽文件至此区域即可上传',
127
  uploadDescription:
128
  '支持单次或批量上传。 严禁上传公司数据或其他违禁文件。',
129
+ chunk: '解析块',
130
  },
131
  knowledgeConfiguration: {
132
  titleDescription: '在这里更新您的知识库详细信息,尤其是解析方法。',
 
249
  chunkMessage: '请输入值!',
250
  },
251
  chat: {
252
+ createAssistant: '新建助理',
253
  assistantSetting: '助理设置',
254
  promptEngine: '提示引擎',
255
  modelSetting: '模型设置',
 
370
  img2txtModel: 'Img2txt模型',
371
  img2txtModelTip:
372
  '所有新创建的知识库都将使用默认的多模块模型。 它可以描述图片或视频。',
373
+ sequence2txtModel: 'Sequence2txt模型',
374
  sequence2txtModelTip:
375
  '所有新创建的知识库都将使用默认的 ASR 模型。 使用此模型将语音翻译为相应的文本。',
376
  workspace: '工作空间',
web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx CHANGED
@@ -1,7 +1,7 @@
1
  import { useDeleteChunkByIds } from '@/hooks/knowledgeHook';
2
  import { useOneNamespaceEffectsLoading } from '@/hooks/storeHooks';
3
  import { DeleteOutlined } from '@ant-design/icons';
4
- import { Checkbox, Form, Input, Modal, Space } from 'antd';
5
  import React, { useCallback, useEffect, useState } from 'react';
6
  import { useTranslation } from 'react-i18next';
7
  import { useDispatch, useSelector } from 'umi';
@@ -115,7 +115,7 @@ const ChunkCreatingModal: React.FC<kFProps> = ({ doc_id, chunkId }) => {
115
  </section>
116
  {chunkId && (
117
  <section>
118
- <p>{t('chunk.function')} *</p>
119
  <Space size={'large'}>
120
  <Checkbox onChange={handleCheck} checked={checked}>
121
  {t('chunk.enabled')}
 
1
  import { useDeleteChunkByIds } from '@/hooks/knowledgeHook';
2
  import { useOneNamespaceEffectsLoading } from '@/hooks/storeHooks';
3
  import { DeleteOutlined } from '@ant-design/icons';
4
+ import { Checkbox, Divider, Form, Input, Modal, Space } from 'antd';
5
  import React, { useCallback, useEffect, useState } from 'react';
6
  import { useTranslation } from 'react-i18next';
7
  import { useDispatch, useSelector } from 'umi';
 
115
  </section>
116
  {chunkId && (
117
  <section>
118
+ <Divider></Divider>
119
  <Space size={'large'}>
120
  <Checkbox onChange={handleCheck} checked={checked}>
121
  {t('chunk.enabled')}
web/src/pages/add-knowledge/index.tsx CHANGED
@@ -10,11 +10,7 @@ import { useEffect, useMemo } from 'react';
10
  import { useTranslation } from 'react-i18next';
11
  import { Link, Outlet, useDispatch, useLocation } from 'umi';
12
  import Siderbar from './components/knowledge-sidebar';
13
- import {
14
- KnowledgeDatasetRouteKey,
15
- KnowledgeRouteKey,
16
- datasetRouteMap,
17
- } from './constant';
18
  import styles from './index.less';
19
 
20
  const KnowledgeAdding = () => {
@@ -55,7 +51,7 @@ const KnowledgeAdding = () => {
55
 
56
  if (datasetActiveKey) {
57
  items.push({
58
- title: datasetRouteMap[datasetActiveKey],
59
  });
60
  }
61
 
 
10
  import { useTranslation } from 'react-i18next';
11
  import { Link, Outlet, useDispatch, useLocation } from 'umi';
12
  import Siderbar from './components/knowledge-sidebar';
13
+ import { KnowledgeDatasetRouteKey, KnowledgeRouteKey } from './constant';
 
 
 
 
14
  import styles from './index.less';
15
 
16
  const KnowledgeAdding = () => {
 
51
 
52
  if (datasetActiveKey) {
53
  items.push({
54
+ title: t(`knowledgeDetails.${datasetActiveKey}`),
55
  });
56
  }
57
 
web/src/pages/chat/index.tsx CHANGED
@@ -204,7 +204,7 @@ const Chat = () => {
204
  <Flex className={styles.chatAppWrapper}>
205
  <Flex flex={1} vertical>
206
  <Button type="primary" onClick={handleShowChatConfigurationModal()}>
207
- Create an Assistant
208
  </Button>
209
  <Divider></Divider>
210
  <Flex className={styles.chatAppContent} vertical gap={10}>
 
204
  <Flex className={styles.chatAppWrapper}>
205
  <Flex flex={1} vertical>
206
  <Button type="primary" onClick={handleShowChatConfigurationModal()}>
207
+ {t('createAssistant')}
208
  </Button>
209
  <Divider></Divider>
210
  <Flex className={styles.chatAppContent} vertical gap={10}>
web/src/pages/user-setting/model.ts CHANGED
@@ -66,6 +66,7 @@ const model: DvaModel<SettingModelState> = {
66
  // };
67
  // authorizationUtil.setUserInfo(userInfo);
68
  if (retcode === 0) {
 
69
  yield put({ type: 'setUserInfo', payload: res });
70
  // localStorage.setItem('userInfo',res.)
71
  }
 
66
  // };
67
  // authorizationUtil.setUserInfo(userInfo);
68
  if (retcode === 0) {
69
+ i18n.changeLanguage(res.language === 'Chinese' ? 'zh' : 'en');
70
  yield put({ type: 'setUserInfo', payload: res });
71
  // localStorage.setItem('userInfo',res.)
72
  }