2023-07-15 12:57:03 +08:00
|
|
|
'use client';
|
|
|
|
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { ValidateMessages } from 'rc-field-form/lib/interface';
|
2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2022-05-10 15:43:29 +08:00
|
|
|
import warning from '../_util/warning';
|
2022-06-22 14:57:09 +08:00
|
|
|
import type { PickerLocale as DatePickerLocale } from '../date-picker/generatePicker';
|
|
|
|
import type { TransferLocale as TransferLocaleForEmpty } from '../empty';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { ModalLocale } from '../modal/locale';
|
|
|
|
import { changeConfirmLocale } from '../modal/locale';
|
|
|
|
import type { PaginationLocale } from '../pagination/Pagination';
|
2022-07-15 11:11:50 +08:00
|
|
|
import type { PopconfirmLocale } from '../popconfirm/PurePanel';
|
2022-06-22 14:57:09 +08:00
|
|
|
import type { TableLocale } from '../table/interface';
|
2023-05-12 14:43:48 +08:00
|
|
|
import type { TourLocale } from '../tour/interface';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { TransferLocale } from '../transfer';
|
2022-06-22 14:57:09 +08:00
|
|
|
import type { UploadLocale } from '../upload/interface';
|
2022-10-10 14:15:08 +08:00
|
|
|
import type { LocaleContextProps } from './context';
|
2020-03-30 22:54:12 +08:00
|
|
|
import LocaleContext from './context';
|
2020-03-11 14:56:01 +08:00
|
|
|
|
2023-03-21 13:08:43 +08:00
|
|
|
export { default as useLocale } from './useLocale';
|
|
|
|
|
2019-07-24 10:34:55 +08:00
|
|
|
export const ANT_MARK = 'internalMark';
|
2016-03-03 16:28:02 +08:00
|
|
|
|
2018-01-13 17:53:25 +08:00
|
|
|
export interface Locale {
|
|
|
|
locale: string;
|
2020-03-11 14:56:01 +08:00
|
|
|
Pagination?: PaginationLocale;
|
2020-03-12 10:49:32 +08:00
|
|
|
DatePicker?: DatePickerLocale;
|
2021-06-03 09:36:04 +08:00
|
|
|
TimePicker?: Record<string, any>;
|
|
|
|
Calendar?: Record<string, any>;
|
2020-03-11 14:56:01 +08:00
|
|
|
Table?: TableLocale;
|
2018-01-13 17:53:25 +08:00
|
|
|
Modal?: ModalLocale;
|
2022-11-02 16:25:28 +08:00
|
|
|
Tour?: TourLocale;
|
2020-03-11 14:56:01 +08:00
|
|
|
Popconfirm?: PopconfirmLocale;
|
2022-10-01 22:17:14 +08:00
|
|
|
Transfer?: TransferLocale;
|
2021-06-03 09:36:04 +08:00
|
|
|
Select?: Record<string, any>;
|
2020-03-11 14:56:01 +08:00
|
|
|
Upload?: UploadLocale;
|
|
|
|
Empty?: TransferLocaleForEmpty;
|
2021-06-03 09:36:04 +08:00
|
|
|
global?: Record<string, any>;
|
|
|
|
PageHeader?: { back: string };
|
|
|
|
Icon?: Record<string, any>;
|
2022-01-18 14:13:41 +08:00
|
|
|
Text?: {
|
|
|
|
edit?: any;
|
|
|
|
copy?: any;
|
|
|
|
copied?: any;
|
|
|
|
expand?: any;
|
|
|
|
};
|
2020-04-18 13:18:51 +08:00
|
|
|
Form?: {
|
2020-08-21 12:58:14 +08:00
|
|
|
optional?: string;
|
2020-04-18 13:18:51 +08:00
|
|
|
defaultValidateMessages: ValidateMessages;
|
|
|
|
};
|
2020-12-07 17:08:48 +08:00
|
|
|
Image?: {
|
|
|
|
preview: string;
|
|
|
|
};
|
2022-12-05 14:15:26 +08:00
|
|
|
QRCode?: {
|
|
|
|
expired: string;
|
|
|
|
refresh: string;
|
|
|
|
};
|
2023-05-12 14:43:48 +08:00
|
|
|
ColorPicker?: {
|
|
|
|
presetEmpty: string;
|
|
|
|
};
|
2018-01-13 17:53:25 +08:00
|
|
|
}
|
|
|
|
|
2016-08-02 16:10:26 +08:00
|
|
|
export interface LocaleProviderProps {
|
2018-01-13 17:53:25 +08:00
|
|
|
locale: Locale;
|
2018-12-13 22:03:12 +08:00
|
|
|
children?: React.ReactNode;
|
2022-10-06 18:53:06 +08:00
|
|
|
/** @internal */
|
2019-07-24 10:34:55 +08:00
|
|
|
_ANT_MARK__?: string;
|
2016-08-02 16:10:26 +08:00
|
|
|
}
|
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
const LocaleProvider: React.FC<LocaleProviderProps> = (props) => {
|
2022-10-10 14:15:08 +08:00
|
|
|
const { locale = {} as Locale, children, _ANT_MARK__ } = props;
|
2019-07-24 10:34:55 +08:00
|
|
|
|
2022-10-10 14:15:08 +08:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
2022-05-10 15:43:29 +08:00
|
|
|
warning(
|
2022-10-10 14:15:08 +08:00
|
|
|
_ANT_MARK__ === ANT_MARK,
|
2019-07-24 10:34:55 +08:00
|
|
|
'LocaleProvider',
|
|
|
|
'`LocaleProvider` is deprecated. Please use `locale` with `ConfigProvider` instead: http://u.ant.design/locale',
|
|
|
|
);
|
2018-04-15 15:09:13 +08:00
|
|
|
}
|
|
|
|
|
2022-10-10 14:15:08 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
changeConfirmLocale(locale && locale.Modal);
|
|
|
|
return () => {
|
|
|
|
changeConfirmLocale();
|
|
|
|
};
|
|
|
|
}, [locale]);
|
2021-03-02 18:05:20 +08:00
|
|
|
|
2022-10-10 14:15:08 +08:00
|
|
|
const getMemoizedContextValue = React.useMemo<LocaleContextProps>(
|
|
|
|
() => ({ ...locale, exist: true }),
|
|
|
|
[locale],
|
|
|
|
);
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2022-10-10 14:15:08 +08:00
|
|
|
return (
|
|
|
|
<LocaleContext.Provider value={getMemoizedContextValue}>{children}</LocaleContext.Provider>
|
|
|
|
);
|
|
|
|
};
|
2022-01-14 18:34:27 +08:00
|
|
|
|
2023-01-08 21:30:41 +08:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
LocaleProvider.displayName = 'LocaleProvider';
|
|
|
|
}
|
|
|
|
|
2022-10-10 14:15:08 +08:00
|
|
|
export default LocaleProvider;
|