@lobehub/chat 0.54.0 → 0.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/package.json +1 -1
- package/src/layout/index.tsx +10 -6
- package/src/locales/create.ts +11 -7
- package/src/locales/resources/en_US.ts +13 -1
- package/src/pages/settings/layout.tsx +7 -7
- package/src/store/global/hooks/index.ts +1 -0
- package/src/store/global/hooks/useHydrated.ts +1 -1
- package/src/store/global/hooks/useOnFinishHydrationGlobal.ts +3 -3
- package/src/locales/index.ts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.54.1](https://github.com/lobehub/lobe-chat/compare/v0.54.0...v0.54.1)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-08-16**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: 修正 i18n 失效的问题.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: 修正 i18n 失效的问题, closes [#80](https://github.com/lobehub/lobe-chat/issues/80) ([b8d957b](https://github.com/lobehub/lobe-chat/commit/b8d957b))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
## [Version 0.54.0](https://github.com/lobehub/lobe-chat/compare/v0.53.0...v0.54.0)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2023-08-15**</sup>
|
package/package.json
CHANGED
package/src/layout/index.tsx
CHANGED
|
@@ -3,22 +3,26 @@ import { App, ConfigProvider } from 'antd';
|
|
|
3
3
|
import { useThemeMode } from 'antd-style';
|
|
4
4
|
import 'antd/dist/reset.css';
|
|
5
5
|
import Zh_CN from 'antd/locale/zh_CN';
|
|
6
|
+
import { changeLanguage } from 'i18next';
|
|
6
7
|
import { PropsWithChildren, memo, useCallback, useEffect } from 'react';
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
+
import { createI18nNext } from '@/locales/create';
|
|
10
|
+
import { useGlobalStore, useOnFinishHydrationGlobal } from '@/store/global';
|
|
9
11
|
import { useSessionStore } from '@/store/session';
|
|
10
12
|
import { GlobalStyle } from '@/styles';
|
|
11
13
|
|
|
12
|
-
import i18n from '../locales';
|
|
13
14
|
import { useStyles } from './style';
|
|
14
15
|
|
|
16
|
+
const i18n = createI18nNext();
|
|
17
|
+
|
|
15
18
|
const Layout = memo<PropsWithChildren>(({ children }) => {
|
|
16
19
|
const { styles } = useStyles();
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
useOnFinishHydrationGlobal((state) => {
|
|
22
|
+
i18n.then(() => {
|
|
23
|
+
changeLanguage(state.settings.language);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
22
26
|
|
|
23
27
|
return (
|
|
24
28
|
<ConfigProvider locale={Zh_CN}>
|
package/src/locales/create.ts
CHANGED
|
@@ -7,12 +7,13 @@ import type { Namespaces } from '@/types/locale';
|
|
|
7
7
|
|
|
8
8
|
import resources from './resources';
|
|
9
9
|
|
|
10
|
-
export const createI18nNext = (namespace?: Namespaces[] | Namespaces) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
: ['error', 'common'];
|
|
10
|
+
export const createI18nNext = (params: { namespace?: Namespaces[] | Namespaces } = {}) => {
|
|
11
|
+
const { namespace } = params;
|
|
12
|
+
|
|
13
|
+
const ns: Namespaces[] = isArray(namespace)
|
|
14
|
+
? ['error', 'common', ...namespace]
|
|
15
|
+
: (['error', 'common', namespace].filter(Boolean) as Namespaces[]);
|
|
16
|
+
|
|
16
17
|
return (
|
|
17
18
|
i18n
|
|
18
19
|
// detect user language
|
|
@@ -23,9 +24,12 @@ export const createI18nNext = (namespace?: Namespaces[] | Namespaces) => {
|
|
|
23
24
|
// init i18next
|
|
24
25
|
// for all options read: https://www.i18next.com/overview/configuration-options
|
|
25
26
|
.init({
|
|
26
|
-
// @ts-ignore
|
|
27
27
|
debug: process.env.NODE_ENV === 'development',
|
|
28
28
|
defaultNS: ns,
|
|
29
|
+
// LanguageDetector config, refs: https://github.com/i18next/i18next-browser-languageDetector
|
|
30
|
+
detection: {
|
|
31
|
+
caches: [],
|
|
32
|
+
},
|
|
29
33
|
fallbackLng: 'zh-CN',
|
|
30
34
|
interpolation: {
|
|
31
35
|
escapeValue: false, // not needed for react as it escapes by default
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import common from '../../../locales/en_US/common.json';
|
|
2
|
+
import empty from '../../../locales/en_US/empty.json';
|
|
3
|
+
import error from '../../../locales/en_US/error.json';
|
|
4
|
+
import plugin from '../../../locales/en_US/plugin.json';
|
|
5
|
+
import setting from '../../../locales/en_US/setting.json';
|
|
6
|
+
|
|
7
|
+
const resources = {
|
|
8
|
+
common,
|
|
9
|
+
empty,
|
|
10
|
+
error,
|
|
11
|
+
plugin,
|
|
12
|
+
setting,
|
|
13
|
+
} as const;
|
|
2
14
|
|
|
3
15
|
export default resources;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import Head from 'next/head';
|
|
2
|
-
import { ReactNode, memo
|
|
2
|
+
import { ReactNode, memo } from 'react';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import { Flexbox } from 'react-layout-kit';
|
|
5
5
|
|
|
6
6
|
import SideBar from '@/features/SideBar';
|
|
7
7
|
import { createI18nNext } from '@/locales/create';
|
|
8
|
-
import { useSwitchSideBarOnInit } from '@/store/global';
|
|
8
|
+
import { useOnFinishHydrationGlobal, useSwitchSideBarOnInit } from '@/store/global';
|
|
9
9
|
import { genSiteHeadTitle } from '@/utils/genSiteHeadTitle';
|
|
10
10
|
|
|
11
|
-
const initI18n = createI18nNext('setting');
|
|
11
|
+
const initI18n = createI18nNext({ namespace: 'setting' });
|
|
12
12
|
|
|
13
13
|
const SettingLayout = memo<{ children: ReactNode }>(({ children }) => {
|
|
14
14
|
const { t } = useTranslation('setting');
|
|
15
15
|
const pageTitle = genSiteHeadTitle(t('header.global'));
|
|
16
16
|
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
initI18n.finally();
|
|
19
|
-
}, []);
|
|
20
|
-
|
|
21
17
|
useSwitchSideBarOnInit('settings');
|
|
22
18
|
|
|
19
|
+
useOnFinishHydrationGlobal(() => {
|
|
20
|
+
initI18n.then(() => {});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
23
|
return (
|
|
24
24
|
<>
|
|
25
25
|
<Head>
|
|
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { useGlobalStore } from '../store';
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const useGlobalHydrated = () => {
|
|
6
6
|
// 根据 sessions 是否有值来判断是否已经初始化
|
|
7
7
|
const hasInited = !!Object.values(useGlobalStore.getState().settings).length;
|
|
8
8
|
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
|
|
3
|
-
import { useGlobalStore } from '../store';
|
|
3
|
+
import { GlobalStore, useGlobalStore } from '../store';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 当 Session 水合完毕后才会执行的 useEffect
|
|
7
7
|
* @param fn
|
|
8
8
|
* @param deps
|
|
9
9
|
*/
|
|
10
|
-
export const useOnFinishHydrationGlobal = (fn: () => void, deps: any[] = []) => {
|
|
10
|
+
export const useOnFinishHydrationGlobal = (fn: (state: GlobalStore) => void, deps: any[] = []) => {
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
const hasRehydrated = useGlobalStore.persist.hasHydrated();
|
|
13
13
|
// 只有当水合完毕后再开始做操作
|
|
14
14
|
if (!hasRehydrated) return;
|
|
15
15
|
|
|
16
|
-
fn();
|
|
16
|
+
fn(useGlobalStore.getState());
|
|
17
17
|
}, deps);
|
|
18
18
|
};
|