Skip to content

Commit b94a830

Browse files
committed
feat(components/loading): 国际化
1 parent 2f4a926 commit b94a830

File tree

7 files changed

+28
-2
lines changed

7 files changed

+28
-2
lines changed

packages/components/src/config-provider/config-provider.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {
22
PopConfirmLocale,
33
DatePickerLocale,
44
CalendarLocale,
5+
LoadingLocale,
56
SelectLocale,
67
InputLocale,
78
EmptyLocale,
@@ -12,6 +13,7 @@ export interface Locale {
1213
datePicker: Partial<DatePickerLocale>;
1314
popConfirm: Partial<PopConfirmLocale>;
1415
calendar: Partial<CalendarLocale>;
16+
loading: Partial<LoadingLocale>;
1517
select: Partial<SelectLocale>;
1618
input: Partial<InputLocale>;
1719
empty: Partial<EmptyLocale>;

packages/components/src/loading/Loading.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import {
55
} from '~/transition';
66
import { useScrollLock, getClasses, useVisible, Z_INDEX } from '@pkg/shared';
77
import React, { useCallback, useMemo, useRef } from 'react';
8+
import { useLocale } from '~/config-provider/useLocale';
89
import { Loading as LoadingIcon } from '@pkg/icons';
910
import { getClassNames } from '@tool-pack/basic';
1011
import { RequiredPart } from '@tool-pack/types';
1112
import { LoadingProps } from './loading.types';
13+
import EnUS from '~/loading/locale/en-US';
1214
import { createPortal } from 'react-dom';
1315
import { Icon } from '~/icon';
1416

@@ -20,7 +22,6 @@ const cls = getClasses(
2022

2123
const defaultProps = {
2224
background: 'var(--t-mask-bg-color)',
23-
text: 'loading...',
2425
zIndex: Z_INDEX,
2526
// color: 'var(--t-text-color)',
2627
mode: 'insert',
@@ -30,8 +31,10 @@ const defaultProps = {
3031
* loading组件
3132
*/
3233
export const Loading: React.FC<LoadingProps> = (props) => {
34+
const locale = useLocale('loading', EnUS);
3335
const {
3436
visible: outerVisible,
37+
text = locale.text,
3538
wrapperAttrs = {},
3639
closeOnClick,
3740
attrs = {},
@@ -43,7 +46,6 @@ export const Loading: React.FC<LoadingProps> = (props) => {
4346
color,
4447
mode,
4548
icon,
46-
text,
4749
} = props as RequiredPart<LoadingProps, keyof typeof defaultProps>;
4850

4951
const wrapperRef = useRef<HTMLDivElement>(null);

packages/components/src/loading/loading.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ export interface LoadingProps extends Omit<PropsBase, 'ref'> {
1414
zIndex?: number;
1515
color?: string;
1616
}
17+
18+
export interface LoadingLocale {
19+
text: string;
20+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { LoadingLocale } from '../loading.types';
2+
3+
const locale: LoadingLocale = {
4+
text: 'loading...',
5+
};
6+
7+
export default locale;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { LoadingLocale } from '../loading.types';
2+
3+
const locale: LoadingLocale = {
4+
text: '加载中...',
5+
};
6+
7+
export default locale;

packages/react-ui/src/locale/en-US.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datePicker from '@pkg/components/date-picker/locale/en-US';
22
import popConfirm from '@pkg/components/pop-confirm/locale/en-US';
33
import calendar from '@pkg/components/calendar/locale/en-US';
4+
import loading from '@pkg/components/loading/locale/en-US';
45
import select from '@pkg/components/select/locale/en-US';
56
import input from '@pkg/components/input/locale/en-US';
67
import empty from '@pkg/components/empty/locale/en-US';
@@ -11,6 +12,7 @@ export default {
1112
popConfirm,
1213
datePicker,
1314
calendar,
15+
loading,
1416
select,
1517
empty,
1618
input,

packages/react-ui/src/locale/zh-CN.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import popConfirm from '@pkg/components/pop-confirm/locale/zh-CN';
22
import datePicker from '@pkg/components/date-picker/locale/zh-CN';
33
import calendar from '@pkg/components/calendar/locale/zh-CN';
4+
import loading from '@pkg/components/loading/locale/zh-CN';
45
import select from '@pkg/components/select/locale/zh-CN';
56
import input from '@pkg/components/input/locale/zh-CN';
67
import empty from '@pkg/components/empty/locale/zh-CN';
@@ -11,6 +12,7 @@ export default {
1112
popConfirm,
1213
datePicker,
1314
calendar,
15+
loading,
1416
select,
1517
empty,
1618
input,

0 commit comments

Comments
 (0)