@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 +8 -0
- package/package.json +3 -3
- package/src/core_app/index.tsx +3 -2
- package/src/editor_json/index.tsx +1 -1
- package/src/i18n.tsx +45 -25
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fe-free/core",
|
|
3
|
-
"version": "6.0.
|
|
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.
|
|
47
|
-
"@fe-free/tool": "6.0.
|
|
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"
|
package/src/core_app/index.tsx
CHANGED
|
@@ -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);
|
package/src/i18n.tsx
CHANGED
|
@@ -29,40 +29,60 @@ const listLanguage = Object.keys(valueEnumLanguage).map((key) => {
|
|
|
29
29
|
};
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
54
|
-
|
|
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
|
-
|
|
66
|
-
|
|
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 };
|