Skip to content

Commit bc16b50

Browse files
committed
feat(components/select): 国际化
1 parent 26a64f0 commit bc16b50

File tree

9 files changed

+34
-5
lines changed

9 files changed

+34
-5
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import type { PopConfirmLocale, CalendarLocale, EmptyLocale } from '../';
1+
import type {
2+
PopConfirmLocale,
3+
CalendarLocale,
4+
SelectLocale,
5+
EmptyLocale,
6+
} from '../';
27

38
export interface Locale {
49
popConfirm: Partial<PopConfirmLocale>;
510
calendar: Partial<CalendarLocale>;
11+
select: Partial<SelectLocale>;
612
empty: Partial<EmptyLocale>;
713
}
814

packages/components/src/select/Select.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ import {
1717
filterOptions,
1818
} from '~/select/utils';
1919
import { useStateWithTrailClear, useForwardRef, getClasses } from '@pkg/shared';
20+
import { useLocale } from '~/config-provider/useLocale';
2021
import { Selection, Menu } from '~/select/components';
2122
import type { RequiredPart } from '@tool-pack/types';
2223
import { transitionCBAdapter } from '~/transition';
2324
import { getClassNames } from '@tool-pack/basic';
2425
import { InputPopover } from '@pkg/components';
2526
import PropTypes from 'prop-types';
27+
import EnUS from './locale/en-US';
2628

2729
const cls = getClasses('select', [], ['selected', 'clearable']);
2830
const defaultProps = {
2931
ignoreComposition: true,
30-
placeholder: 'select',
3132
widthByTrigger: true,
3233
placement: 'bottom',
3334
showArrow: false,
@@ -41,13 +42,14 @@ const _Select: React.FC<SelectStaticProps> = React.forwardRef<
4142
HTMLLabelElement,
4243
SelectStaticProps
4344
>((props, ref) => {
45+
const locale = useLocale('select', EnUS);
4446
const {
47+
placeholder = locale.placeholder,
4548
ignoreComposition,
4649
onVisibleChange,
4750
controllerRef,
4851
popoverAttrs,
4952
maxTagCount,
50-
placeholder,
5153
attrs = {},
5254
filterable,
5355
clearable,

packages/components/src/select/demo/multiple.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const App: React.FC = () => {
1818
setValue(value);
1919
console.log(values, options);
2020
}}
21-
placeholder="select"
2221
options={options}
2322
value={value}
2423
multiple
@@ -29,7 +28,6 @@ const App: React.FC = () => {
2928
setValue(value);
3029
console.log(values, options);
3130
}}
32-
placeholder="select"
3331
options={options}
3432
value={value}
3533
disabled

packages/components/src/select/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type {
44
SelectOptionsItem,
55
SelectDivider,
66
SelectOption,
7+
SelectLocale,
78
SelectProps,
89
} from './select.types';
910
export * from './Select';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { SelectLocale } from '../select.types';
2+
3+
const locale: SelectLocale = {
4+
placeholder: 'Please select',
5+
};
6+
7+
export default locale;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { SelectLocale } from '../select.types';
2+
3+
const locale: SelectLocale = {
4+
placeholder: '请选择',
5+
};
6+
7+
export default locale;

packages/components/src/select/select.types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,7 @@ export type SelectFC = <
107107
>(
108108
props: SelectProps<Multiple, ValueType>,
109109
) => React.ReactElement;
110+
111+
export interface SelectLocale {
112+
placeholder: string;
113+
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import popConfirm from '@pkg/components/pop-confirm/locale/en-US';
22
import calendar from '@pkg/components/calendar/locale/en-US';
3+
import select from '@pkg/components/select/locale/en-US';
34
import empty from '@pkg/components/empty/locale/en-US';
45
import type { Locale } from '@pkg/components';
56

67
export default {
78
popConfirm,
89
calendar,
10+
select,
911
empty,
1012
} satisfies Locale;

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

+2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import popConfirm from '@pkg/components/pop-confirm/locale/zh-CN';
22
import calendar from '@pkg/components/calendar/locale/zh-CN';
33
import empty from '@pkg/components/empty/locale/zh-CN';
44
import type { Locale } from '@pkg/components';
5+
import select from '~/select/locale/zh-CN';
56

67
export default {
78
popConfirm,
89
calendar,
10+
select,
911
empty,
1012
} satisfies Locale;

0 commit comments

Comments
 (0)