@fe-free/core 4.0.3 → 4.0.5
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 +15 -0
- package/package.json +8 -4
- package/src/core_app/index.tsx +26 -8
- package/src/crud_of_pure/crud_of_pure.stories.tsx +3 -0
- package/src/i18n.tsx +63 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @fe-free/core
|
|
2
2
|
|
|
3
|
+
## 4.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @fe-free/icons@4.0.5
|
|
8
|
+
- @fe-free/tool@4.0.5
|
|
9
|
+
|
|
10
|
+
## 4.0.4
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- feat: i18n
|
|
15
|
+
- @fe-free/icons@4.0.4
|
|
16
|
+
- @fe-free/tool@4.0.4
|
|
17
|
+
|
|
3
18
|
## 4.0.3
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fe-free/core",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"author": "",
|
|
@@ -45,11 +45,15 @@
|
|
|
45
45
|
"@ant-design/pro-components": "2.8.9",
|
|
46
46
|
"antd": "^5.27.1",
|
|
47
47
|
"dayjs": "~1.11.10",
|
|
48
|
+
"i18next": "^25.7.2",
|
|
49
|
+
"i18next-browser-languagedetector": "^8.2.0",
|
|
50
|
+
"i18next-icu": "^2.4.1",
|
|
48
51
|
"react": "^19.2.0",
|
|
49
|
-
"
|
|
50
|
-
"@fe-free/
|
|
52
|
+
"react-i18next": "^16.4.0",
|
|
53
|
+
"@fe-free/icons": "4.0.5",
|
|
54
|
+
"@fe-free/tool": "4.0.5"
|
|
51
55
|
},
|
|
52
56
|
"scripts": {
|
|
53
|
-
"
|
|
57
|
+
"i18n-extract": "rm -rf ./src/locales/zh-CN && npx i18next-cli extract"
|
|
54
58
|
}
|
|
55
59
|
}
|
package/src/core_app/index.tsx
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { ProConfigProvider } from '@ant-design/pro-components';
|
|
2
2
|
import { useTitle } from 'ahooks';
|
|
3
3
|
import { App, ConfigProvider } from 'antd';
|
|
4
|
+
import enUS from 'antd/locale/en_US';
|
|
4
5
|
import zhCN from 'antd/locale/zh_CN';
|
|
5
6
|
import classNames from 'classnames';
|
|
6
7
|
import { merge } from 'lodash-es';
|
|
7
8
|
import { useEffect, useMemo } from 'react';
|
|
9
|
+
import { useTranslation } from 'react-i18next';
|
|
8
10
|
import { BrowserRouter as Router, useNavigate } from 'react-router-dom';
|
|
11
|
+
import { EnumLanguage, I18nProvider } from '../i18n';
|
|
9
12
|
import { routeTool } from '../route';
|
|
10
13
|
import { customValueTypeMap } from '../value_type_map';
|
|
11
14
|
import { themeConfig } from './config';
|
|
@@ -94,8 +97,7 @@ function SetRouteTool({ basename }: { basename: string }) {
|
|
|
94
97
|
return null;
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
function CoreApp(props: {
|
|
100
|
+
interface CoreAppProps {
|
|
99
101
|
basename: string;
|
|
100
102
|
name?: string;
|
|
101
103
|
enableCheckUpdate?: boolean;
|
|
@@ -107,7 +109,9 @@ function CoreApp(props: {
|
|
|
107
109
|
customConfig?: {
|
|
108
110
|
hiddenFormItemLabelColon?: boolean;
|
|
109
111
|
};
|
|
110
|
-
}
|
|
112
|
+
}
|
|
113
|
+
/** 提供一些基础的组 APP 功能 */
|
|
114
|
+
function CoreAppBase(props: CoreAppProps) {
|
|
111
115
|
const {
|
|
112
116
|
basename,
|
|
113
117
|
name,
|
|
@@ -120,6 +124,8 @@ function CoreApp(props: {
|
|
|
120
124
|
customConfig,
|
|
121
125
|
} = props;
|
|
122
126
|
|
|
127
|
+
const { i18n } = useTranslation();
|
|
128
|
+
|
|
123
129
|
useTitle(name || '');
|
|
124
130
|
|
|
125
131
|
useEffect(() => {
|
|
@@ -133,6 +139,14 @@ function CoreApp(props: {
|
|
|
133
139
|
return merge(themeConfig, configProviderProps?.theme);
|
|
134
140
|
}, [configProviderProps?.theme]);
|
|
135
141
|
|
|
142
|
+
const locale = useMemo(() => {
|
|
143
|
+
if (configProviderProps?.locale) {
|
|
144
|
+
return configProviderProps.locale;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return i18n.language === EnumLanguage.EN_US ? enUS : zhCN;
|
|
148
|
+
}, [configProviderProps?.locale, i18n.language]);
|
|
149
|
+
|
|
136
150
|
return (
|
|
137
151
|
<ProConfigProvider
|
|
138
152
|
{...proConfigProviderProps}
|
|
@@ -140,11 +154,7 @@ function CoreApp(props: {
|
|
|
140
154
|
valueTypeMap={{ ...customValueTypeMap, ...proConfigProviderProps?.valueTypeMap }}
|
|
141
155
|
>
|
|
142
156
|
{/* 集成好 locale */}
|
|
143
|
-
<ConfigProvider
|
|
144
|
-
{...configProviderProps}
|
|
145
|
-
locale={configProviderProps?.locale || zhCN}
|
|
146
|
-
theme={theme}
|
|
147
|
-
>
|
|
157
|
+
<ConfigProvider {...configProviderProps} locale={locale} theme={theme}>
|
|
148
158
|
<App
|
|
149
159
|
{...appProps}
|
|
150
160
|
className={classNames('fec-app', appProps?.className, {
|
|
@@ -162,4 +172,12 @@ function CoreApp(props: {
|
|
|
162
172
|
);
|
|
163
173
|
}
|
|
164
174
|
|
|
175
|
+
function CoreApp(props: CoreAppProps) {
|
|
176
|
+
return (
|
|
177
|
+
<I18nProvider>
|
|
178
|
+
<CoreAppBase {...props} />
|
|
179
|
+
</I18nProvider>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
165
183
|
export { CoreApp };
|
package/src/i18n.tsx
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import i18n from 'i18next';
|
|
2
|
+
import LanguageDetector from 'i18next-browser-languagedetector';
|
|
3
|
+
import ICU from 'i18next-icu';
|
|
4
|
+
import { I18nextProvider, initReactI18next } from 'react-i18next';
|
|
5
|
+
|
|
6
|
+
enum EnumLanguage {
|
|
7
|
+
ZH_CN = 'zh-CN',
|
|
8
|
+
EN_US = 'en-US',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const valueEnumLanguage = {
|
|
12
|
+
[EnumLanguage.ZH_CN]: {
|
|
13
|
+
text: '中文',
|
|
14
|
+
value: EnumLanguage.ZH_CN,
|
|
15
|
+
},
|
|
16
|
+
[EnumLanguage.EN_US]: {
|
|
17
|
+
text: '英文',
|
|
18
|
+
value: EnumLanguage.EN_US,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const listLanguage = Object.keys(valueEnumLanguage).map((key) => {
|
|
23
|
+
const item = valueEnumLanguage[key];
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
value: item.value !== undefined ? item.value : key,
|
|
27
|
+
label: item.text,
|
|
28
|
+
originData: item.data,
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
function initI18n({ enTranslation }) {
|
|
33
|
+
const cacheLng = localStorage.getItem('i18nextLng') || EnumLanguage.ZH_CN;
|
|
34
|
+
const lng = listLanguage.find((item) => item.value === cacheLng) ? cacheLng : EnumLanguage.ZH_CN;
|
|
35
|
+
|
|
36
|
+
i18n
|
|
37
|
+
.use(LanguageDetector)
|
|
38
|
+
.use(initReactI18next)
|
|
39
|
+
.use(ICU)
|
|
40
|
+
.init({
|
|
41
|
+
resources: {
|
|
42
|
+
[EnumLanguage.ZH_CN]: {
|
|
43
|
+
translation: {},
|
|
44
|
+
},
|
|
45
|
+
[EnumLanguage.EN_US]: {
|
|
46
|
+
translation: {
|
|
47
|
+
...enTranslation,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
lng,
|
|
52
|
+
fallbackLng: EnumLanguage.ZH_CN,
|
|
53
|
+
interpolation: {
|
|
54
|
+
escapeValue: false,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function I18nProvider({ children }: { children: React.ReactNode }) {
|
|
60
|
+
return <I18nextProvider i18n={i18n}>{children}</I18nextProvider>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { EnumLanguage, I18nProvider, initI18n, listLanguage, valueEnumLanguage };
|