Skip to content

Commit 013ddfb

Browse files
authored
feat(configprovider): 3.x support locale provider for RC (#528)
* feat(configprovider): support provider for RC * feat(configprovider): migrate locale type to useLocale * fix(configprovider): change Locale path and remove sass_binary_site * fix: change jest.config.js transform * fix(configprovider): remove all cn add locale * fix(configprovider): fix check-type error * fix(configprovider): update en locale text * feat(configprovider): change ConfigProvider value and getLocale return value
1 parent 798e662 commit 013ddfb

26 files changed

Lines changed: 493 additions & 97 deletions

File tree

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
transformIgnorePatterns: ['/node_modules/', 'lib', 'dist'],
66
testPathIgnorePatterns: ['/node_modules/'],
77
transform: {
8-
'^.+\\.[jt]s?(x)$': 'babel-jest',
8+
'^.+\\.(ts|tsx|js|jsx)$': 'babel-jest',
99
},
1010
testMatch: [
1111
'**/__tests__/**/(*.)+(spec|test).[jt]s?(x)',

src/components/blockHeader/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState } from 'react';
22
import { QuestionCircleOutlined, UpOutlined } from '@ant-design/icons';
33
import { Tooltip } from 'antd';
4+
import useLocale from '../locale/useLocale';
45

56
export interface BlockHeaderProps {
67
// 标题
@@ -60,6 +61,9 @@ const BlockHeader: React.FC<BlockHeaderProps> = function (props) {
6061
let bottomStyle;
6162
if (hasBottom) bottomStyle = { marginBottom: 16 };
6263
if (spaceBottom) bottomStyle = { marginBottom: spaceBottom };
64+
65+
const locale = useLocale('BlockHeader');
66+
6367
const [expand, setExpand] = useState(defaultExpand);
6468

6569
const handleExpand = (expand) => {
@@ -87,7 +91,7 @@ const BlockHeader: React.FC<BlockHeaderProps> = function (props) {
8791
{addonAfter && <div className={`${prefixCls}-addonAfter-box`}>{addonAfter}</div>}
8892
{children && (
8993
<div className={`${prefixCls}-collapse-box`}>
90-
<div className="text">{expand ? '收起' : '展开'}</div>
94+
<div className="text">{expand ? locale.collapse : locale.expand}</div>
9195
<UpOutlined className={`icon ${expand ? 'up' : 'down'}`} />
9296
</div>
9397
)}

src/components/chromeDownload/index.tsx

Lines changed: 14 additions & 7 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
3+
import { LocaleContext } from '../locale/useLocale';
4+
5+
const ConfigProvider = ({ locale, children }) => {
6+
return <LocaleContext.Provider value={{ locale }}>{children}</LocaleContext.Provider>;
7+
};
8+
9+
export default ConfigProvider;

src/components/copyIcon/index.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import * as React from 'react';
22
import { Tooltip, message } from 'antd';
33
import { CopyOutlined } from '@ant-design/icons';
4+
import useLocale, { Locale } from '../locale/useLocale';
45

56
export interface CopyIconProps {
67
text: string;
78
style?: React.CSSProperties;
89
title?: string;
910
customRender?: React.ReactNode;
11+
locale?: Locale['CopyIcon'];
1012
}
1113

12-
export default class CopyIcon extends React.Component<any, any> {
14+
class CopyIcon extends React.Component<CopyIconProps, any> {
1315
fakeHandlerCallback: () => void;
1416
fakeHandler: EventListener | void;
1517
fakeElem: HTMLTextAreaElement;
@@ -82,15 +84,16 @@ export default class CopyIcon extends React.Component<any, any> {
8284
}
8385

8486
handleResult(succeeded: any) {
87+
const { locale } = this.props;
8588
if (succeeded) {
86-
message.success('复制成功');
89+
message.success(locale.copied);
8790
} else {
88-
message.error('不支持');
91+
message.error(locale.notSupport);
8992
}
9093
}
9194

9295
render() {
93-
let { customRender, text, style, title, ...rest } = this.props;
96+
let { customRender, text, style, title, locale, ...rest } = this.props;
9497

9598
style = {
9699
cursor: 'pointer',
@@ -101,7 +104,7 @@ export default class CopyIcon extends React.Component<any, any> {
101104
return customRender ? (
102105
<span onClick={this.copy.bind(this, text)}>{customRender}</span>
103106
) : (
104-
<Tooltip placement="right" title={title || '复制'}>
107+
<Tooltip placement="right" title={title || locale.copy}>
105108
<CopyOutlined
106109
{...rest}
107110
className="c-copyIcon"
@@ -112,3 +115,10 @@ export default class CopyIcon extends React.Component<any, any> {
112115
);
113116
}
114117
}
118+
119+
const CopyIconWrapper = (props: Omit<CopyIconProps, 'locale'>) => {
120+
const locale = useLocale('CopyIcon');
121+
return <CopyIcon {...props} locale={locale} />;
122+
};
123+
124+
export default CopyIconWrapper;

src/components/editCell/index.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@ import React from 'react';
22
import { Input } from 'antd';
33
import EllipsisText from '../ellipsisText';
44
import classNames from 'classnames';
5+
import useLocale, { Locale } from '../locale/useLocale';
56

67
type EditType = string | number;
78
export interface EditCellProps {
89
className?: string;
910
value: string;
1011
keyField: string;
1112
isView?: boolean;
13+
locale?: Locale['EditCell'];
1214
onHandleEdit: (keyField: string, editValue: EditType) => void;
1315
}
1416
export interface EditCellStates {
1517
isEdit: boolean;
1618
editValue: EditType;
1719
}
1820

19-
export default class EditCell extends React.PureComponent<EditCellProps, EditCellStates> {
21+
class EditCell extends React.PureComponent<EditCellProps, EditCellStates> {
2022
state: EditCellStates = {
2123
isEdit: false,
2224
editValue: '',
@@ -47,7 +49,7 @@ export default class EditCell extends React.PureComponent<EditCellProps, EditCel
4749

4850
render() {
4951
const { isEdit, editValue } = this.state;
50-
const { isView, className = '' } = this.props;
52+
const { isView, className = '', locale } = this.props;
5153
return (
5254
<div className={classNames('dtc-edit-Cell', className)}>
5355
{isEdit ? (
@@ -57,16 +59,23 @@ export default class EditCell extends React.PureComponent<EditCellProps, EditCel
5759
style={{ width: 150, lineHeight: 24, height: 24 }}
5860
onChange={this.onChangeEdit}
5961
/>
60-
<a onClick={this.onOkEdit}>完成</a>
61-
<a onClick={this.onCancelEdit}>取消</a>
62+
<a onClick={this.onOkEdit}>{locale.complete}</a>
63+
<a onClick={this.onCancelEdit}>{locale.cancel}</a>
6264
</div>
6365
) : (
6466
<>
6567
<EllipsisText value={editValue} maxWidth={120} />
66-
{!isView && <a onClick={this.onEdit}>修改</a>}
68+
{!isView && <a onClick={this.onEdit}>{locale.modify}</a>}
6769
</>
6870
)}
6971
</div>
7072
);
7173
}
7274
}
75+
76+
const EditCellWrapper = (props: Omit<EditCellProps, 'locale'>) => {
77+
const locale = useLocale('EditCell');
78+
return <EditCell {...props} locale={locale} />;
79+
};
80+
81+
export default EditCellWrapper;

src/components/editInput/__tests__/editInput.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('test edit input', () => {
3333
});
3434
test('should render message when length more then max', () => {
3535
fireEvent.change(element, { target: { value: '12345678910' } });
36-
expect(wrapper.getByText('字符长度不可超过10')).toBeInTheDocument();
36+
expect(wrapper.getByText('字符长度不可超过${max}')).toBeInTheDocument();
3737
expect(element.value).toEqual('1234567891');
3838
});
3939

src/components/editInput/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import React from 'react';
22
import { Input, message } from 'antd';
3+
import useLocale, { Locale } from '../locale/useLocale';
34
export interface EditInputProps {
45
value?: string | number;
56
onChange?: (e) => void;
67
max?: number;
8+
locale?: Locale['EditInput'];
79
[propName: string]: any;
810
}
911

1012
export interface EditInputPropsStates {
1113
value: string | number;
1214
}
13-
export default class EditInput extends React.PureComponent<EditInputProps, EditInputPropsStates> {
15+
class EditInput extends React.PureComponent<EditInputProps, EditInputPropsStates> {
1416
constructor(props: EditInputProps) {
1517
super(props);
1618
this.state = {
@@ -34,10 +36,11 @@ export default class EditInput extends React.PureComponent<EditInputProps, EditI
3436
this.props.onChange(e);
3537
};
3638
onChangeValue = (e: React.ChangeEvent<HTMLInputElement>) => {
39+
const { locale } = this.props;
3740
const value = e.target.value;
3841
const { max = 64 } = this.props;
3942
if (value && max && value.length > max) {
40-
message.warning(`字符长度不可超过${max}`);
43+
message.warning(locale.description);
4144
this.setState({
4245
value: value.substring(0, max),
4346
});
@@ -61,3 +64,10 @@ export default class EditInput extends React.PureComponent<EditInputProps, EditI
6164
);
6265
}
6366
}
67+
68+
const EditInputWrapper = (props: Omit<EditInputProps, 'locale'>) => {
69+
const locale = useLocale('EditInput');
70+
return <EditInput {...props} locale={locale} />;
71+
};
72+
73+
export default EditInputWrapper;

src/components/fullscreen/index.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Button } from 'antd';
33

44
import MyIcon from './icon';
55
import KeyEventListener from '../keyEventListener';
6+
import useLocale, { Locale } from '../locale/useLocale';
67

78
const { KeyCombiner } = KeyEventListener;
89
declare let document: any;
@@ -14,12 +15,13 @@ export interface FullscreenProps {
1415
iconStyle?: object;
1516
fullIcon?: React.ReactNode;
1617
exitFullIcon?: React.ReactNode;
18+
locale?: Locale['Fullscreen'];
1719
[propName: string]: any;
1820
}
1921
export interface FullscreenState {
2022
isFullScreen: boolean;
2123
}
22-
export default class Fullscreen extends React.Component<FullscreenProps, FullscreenState> {
24+
class Fullscreen extends React.Component<FullscreenProps, FullscreenState> {
2325
state: FullscreenState = {
2426
isFullScreen: false,
2527
};
@@ -136,8 +138,8 @@ export default class Fullscreen extends React.Component<FullscreenProps, Fullscr
136138
};
137139

138140
render() {
139-
const { themeDark, fullIcon, exitFullIcon, iconStyle, ...other } = this.props;
140-
const title = this.state.isFullScreen ? '退出全屏' : '全屏';
141+
const { themeDark, fullIcon, exitFullIcon, iconStyle, locale, ...other } = this.props;
142+
const title = this.state.isFullScreen ? locale.exitFull : locale.full;
141143
// const iconType = this.state.isFullScreen ? 'exit-fullscreen' : 'fullscreen';
142144
const customIcon = this.state.isFullScreen ? exitFullIcon : fullIcon;
143145
return (
@@ -167,3 +169,10 @@ export default class Fullscreen extends React.Component<FullscreenProps, Fullscr
167169
);
168170
}
169171
}
172+
173+
const FullscreenWrapper = (props: Omit<FullscreenProps, 'locale'>) => {
174+
const locale = useLocale('Fullscreen');
175+
return <Fullscreen {...props} locale={locale} />;
176+
};
177+
178+
export default FullscreenWrapper;

src/components/globalLoading/index.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import classNames from 'classnames';
22
import React from 'react';
3+
import useLocale, { Locale } from '../locale/useLocale';
34

45
export interface GlobalLoadingProps {
56
className?: string;
@@ -8,19 +9,23 @@ export interface GlobalLoadingProps {
89
mainBackground?: string;
910
circleBackground?: string;
1011
titleColor?: string;
12+
locale?: Locale['GlobalLoading'];
1113
}
1214

13-
export default class GlobalLoading extends React.Component<GlobalLoadingProps, any> {
15+
class GlobalLoading extends React.Component<GlobalLoadingProps, any> {
1416
render() {
1517
const {
1618
prefix = '',
17-
loadingTitle = '应用加载中,请等候~',
19+
loadingTitle,
1820
mainBackground = '#F2F7FA',
1921
circleBackground = '#1D78FF',
2022
titleColor = '#3D446E',
2123
className = '',
24+
locale,
2225
} = this.props;
2326

27+
const newLoadingTitle = loadingTitle || locale.loading;
28+
2429
return (
2530
<div
2631
className={classNames('dtc-loading-wrapper', className)}
@@ -31,7 +36,7 @@ export default class GlobalLoading extends React.Component<GlobalLoadingProps, a
3136
<div
3237
className="dtc-loading-title"
3338
style={{ color: titleColor }}
34-
>{`${prefix} ${loadingTitle}`}</div>
39+
>{`${prefix} ${newLoadingTitle}`}</div>
3540
<div className="dtc-bouncy-wrap">
3641
<div className="dtc-dot-icon dtc-dc1">
3742
<div className="dtc-dot" style={{ background: circleBackground }}></div>
@@ -48,3 +53,10 @@ export default class GlobalLoading extends React.Component<GlobalLoadingProps, a
4853
);
4954
}
5055
}
56+
57+
const GlobalLoadingWrapper = (props: Omit<GlobalLoadingProps, 'locale'>) => {
58+
const locale = useLocale('GlobalLoading');
59+
return <GlobalLoading {...props} locale={locale} />;
60+
};
61+
62+
export default GlobalLoadingWrapper;

0 commit comments

Comments
 (0)