@fe-free/core 6.0.9 → 6.0.10

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
@@ -1,5 +1,13 @@
1
1
  # @fe-free/core
2
2
 
3
+ ## 6.0.10
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: i18n
8
+ - @fe-free/icons@6.0.10
9
+ - @fe-free/tool@6.0.10
10
+
3
11
  ## 6.0.9
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "6.0.9",
3
+ "version": "6.0.10",
4
4
  "description": "React 业务核心组件库:CRUD、ProForm 扩展、布局、路由、树、上传等(Antd + ProComponents)",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -43,8 +43,8 @@
43
43
  "i18next-icu": "^2.4.1",
44
44
  "react": "^19.2.0",
45
45
  "react-i18next": "^16.4.0",
46
- "@fe-free/icons": "6.0.9",
47
- "@fe-free/tool": "6.0.9"
46
+ "@fe-free/icons": "6.0.10",
47
+ "@fe-free/tool": "6.0.10"
48
48
  },
49
49
  "scripts": {
50
50
  "i18n-extract": "rm -rf ./src/locales/zh-CN && npx i18next-cli extract"
@@ -8,6 +8,7 @@ import { merge } from 'lodash-es';
8
8
  import { useEffect, useMemo } from 'react';
9
9
  import { useTranslation } from 'react-i18next';
10
10
  import { BrowserRouter as Router, useNavigate } from 'react-router-dom';
11
+
11
12
  import { EnumLanguage, I18nProvider } from '../i18n';
12
13
  import { routeTool } from '../route';
13
14
  import { customValueTypeMap } from '../value_type_map';
@@ -86,7 +87,7 @@ function CheckUpdate({ basename }: { basename: string }) {
86
87
  return () => {
87
88
  clearInterval(timer);
88
89
  };
89
- }, [t]);
90
+ }, [t, basename, modal]);
90
91
 
91
92
  return null;
92
93
  }
@@ -139,7 +140,7 @@ function CoreAppBase(props: CoreAppProps) {
139
140
  if (window.location.pathname === '/' && basename !== '/' && basename !== '') {
140
141
  window.location.href = basename;
141
142
  }
142
- }, []);
143
+ }, [basename]);
143
144
 
144
145
  const theme = useMemo(() => {
145
146
  return merge(themeConfig, configProviderProps?.theme);
@@ -17,7 +17,7 @@ function EditorJSON({ value, onChange, readonly, mode, mainMenuBar }: EditorJSON
17
17
  const refOnChange = useRef(onChange);
18
18
 
19
19
  useEffect(() => {
20
- refEditor.current?.update({
20
+ void refEditor.current?.update({
21
21
  text: value || '',
22
22
  });
23
23
  }, [value]);
package/src/i18n.tsx CHANGED
@@ -29,40 +29,60 @@ const listLanguage = Object.keys(valueEnumLanguage).map((key) => {
29
29
  };
30
30
  });
31
31
 
32
- function initI18n({ enTranslation }) {
33
- const cacheLng = localStorage.getItem('i18nextLng') || EnumLanguage.ZH_CN;
32
+ let hasSetupPlugins = false;
33
+
34
+ function getDefaultLng() {
35
+ if (typeof window === 'undefined') {
36
+ return EnumLanguage.ZH_CN;
37
+ }
38
+
39
+ const cacheLng = window.localStorage.getItem('i18nextLng') || EnumLanguage.ZH_CN;
34
40
  const lng = listLanguage.find((item) => item.value === cacheLng) ? cacheLng : EnumLanguage.ZH_CN;
35
41
 
36
- console.log('initI18n', 'cacheLng', cacheLng, 'lng', lng);
37
-
38
- i18n
39
- .use(LanguageDetector)
40
- .use(initReactI18next)
41
- .use(ICU)
42
- .init({
43
- resources: {
44
- [EnumLanguage.ZH_CN]: {
45
- translation: {},
46
- },
47
- [EnumLanguage.EN_US]: {
48
- translation: {
49
- ...enTranslation,
50
- },
51
- },
42
+ return lng;
43
+ }
44
+
45
+ function initI18n({ enTranslation = {} }: { enTranslation?: Record<string, unknown> } = {}) {
46
+ if (i18n.isInitialized) {
47
+ i18n.addResourceBundle(EnumLanguage.EN_US, 'translation', enTranslation, true, true);
48
+ return;
49
+ }
50
+
51
+ if (!hasSetupPlugins) {
52
+ i18n.use(LanguageDetector).use(initReactI18next).use(ICU);
53
+ hasSetupPlugins = true;
54
+ }
55
+
56
+ const lng = getDefaultLng();
57
+ console.log('initI18n', lng);
58
+
59
+ void i18n.init({
60
+ resources: {
61
+ [EnumLanguage.ZH_CN]: {
62
+ translation: {},
52
63
  },
53
- lng,
54
- fallbackLng: EnumLanguage.ZH_CN,
55
- interpolation: {
56
- escapeValue: false,
64
+ [EnumLanguage.EN_US]: {
65
+ translation: enTranslation,
57
66
  },
58
- });
67
+ },
68
+ lng,
69
+ fallbackLng: EnumLanguage.ZH_CN,
70
+ interpolation: {
71
+ escapeValue: false,
72
+ },
73
+ });
59
74
  }
60
75
 
61
76
  function I18nProvider({ children }: { children: React.ReactNode }) {
77
+ initI18n();
62
78
  return <I18nextProvider i18n={i18n}>{children}</I18nextProvider>;
63
79
  }
64
80
 
65
- // @ts-ignore
66
- window._i18n = i18n;
81
+ initI18n();
82
+
83
+ if (typeof window !== 'undefined') {
84
+ // @ts-ignore
85
+ window._i18n = i18n;
86
+ }
67
87
 
68
88
  export { EnumLanguage, I18nProvider, initI18n, listLanguage, valueEnumLanguage };