@lobehub/chat 0.98.1 → 0.98.2

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 CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.98.2](https://github.com/lobehub/lobe-chat/compare/v0.98.1...v0.98.2)
6
+
7
+ <sup>Released on **2023-11-07**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: Refactor antd locale file to useSWR.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Code refactoring
19
+
20
+ - **misc**: Refactor antd locale file to useSWR ([2e1cd7c](https://github.com/lobehub/lobe-chat/commit/2e1cd7c))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ### [Version 0.98.1](https://github.com/lobehub/lobe-chat/compare/v0.98.0...v0.98.1)
6
31
 
7
32
  <sup>Released on **2023-11-07**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.98.1",
3
+ "version": "0.98.2",
4
4
  "description": "An open-source, extensible (Function Calling), high-performance chatbot framework. It supports one-click free deployment of your private ChatGPT/LLM web application",
5
5
  "keywords": [
6
6
  "chatbot",
@@ -1,6 +1,6 @@
1
1
  import { ConfigProvider } from 'antd';
2
- import defaultLocale from 'antd/locale/en_US';
3
2
  import { PropsWithChildren, memo, useState } from 'react';
3
+ import useSWR from 'swr';
4
4
 
5
5
  import { createI18nNext } from '@/locales/create';
6
6
  import { useOnFinishHydrationGlobal } from '@/store/global';
@@ -12,7 +12,11 @@ interface LocaleLayoutProps extends PropsWithChildren {
12
12
  }
13
13
 
14
14
  const InnerLocale = memo<LocaleLayoutProps>(({ children, lang }) => {
15
- const [locale, setLocale] = useState(defaultLocale);
15
+ const { data: locale } = useSWR(
16
+ lang,
17
+ async () =>
18
+ await import(`antd/locale/${lang?.includes('-') ? lang?.replace('-', '_') : 'en-US'}.js`),
19
+ );
16
20
  const [i18n] = useState(createI18nNext(lang));
17
21
 
18
22
  // if run on server side, init i18n instance everytime
@@ -27,19 +31,10 @@ const InnerLocale = memo<LocaleLayoutProps>(({ children, lang }) => {
27
31
  });
28
32
  }
29
33
 
30
- const getLocale = async (localeName: string) => {
31
- setLocale((await import(`antd/locale/${localeName}.js`)) as any);
32
- };
33
-
34
34
  useOnFinishHydrationGlobal((s) => {
35
35
  if (s.settings.language === 'auto') {
36
36
  switchLang('auto');
37
37
  }
38
-
39
- if (lang?.includes('-') && lang !== 'en-US') {
40
- const localeName = lang?.replace('-', '_');
41
- getLocale(localeName);
42
- }
43
38
  }, []);
44
39
 
45
40
  return <ConfigProvider locale={locale}>{children}</ConfigProvider>;