You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.5 KiB
91 lines
2.5 KiB
3 years ago
|
import type { ValidateMessages } from 'rc-field-form/lib/interface';
|
||
2 years ago
|
import * as React from 'react';
|
||
3 years ago
|
import warning from '../_util/warning';
|
||
2 years ago
|
import type { PickerLocale as DatePickerLocale } from '../date-picker/generatePicker';
|
||
|
import type { TransferLocale as TransferLocaleForEmpty } from '../empty';
|
||
3 years ago
|
import type { ModalLocale } from '../modal/locale';
|
||
2 years ago
|
import type { TourLocale } from '../tour/interface';
|
||
3 years ago
|
import { changeConfirmLocale } from '../modal/locale';
|
||
|
import type { PaginationLocale } from '../pagination/Pagination';
|
||
2 years ago
|
import type { PopconfirmLocale } from '../popconfirm/PurePanel';
|
||
2 years ago
|
import type { TableLocale } from '../table/interface';
|
||
3 years ago
|
import type { TransferLocale } from '../transfer';
|
||
2 years ago
|
import type { UploadLocale } from '../upload/interface';
|
||
2 years ago
|
import type { LocaleContextProps } from './context';
|
||
5 years ago
|
import LocaleContext from './context';
|
||
5 years ago
|
|
||
5 years ago
|
export const ANT_MARK = 'internalMark';
|
||
9 years ago
|
|
||
7 years ago
|
export interface Locale {
|
||
|
locale: string;
|
||
5 years ago
|
Pagination?: PaginationLocale;
|
||
5 years ago
|
DatePicker?: DatePickerLocale;
|
||
4 years ago
|
TimePicker?: Record<string, any>;
|
||
|
Calendar?: Record<string, any>;
|
||
5 years ago
|
Table?: TableLocale;
|
||
7 years ago
|
Modal?: ModalLocale;
|
||
2 years ago
|
Tour?: TourLocale;
|
||
5 years ago
|
Popconfirm?: PopconfirmLocale;
|
||
2 years ago
|
Transfer?: TransferLocale;
|
||
4 years ago
|
Select?: Record<string, any>;
|
||
5 years ago
|
Upload?: UploadLocale;
|
||
|
Empty?: TransferLocaleForEmpty;
|
||
4 years ago
|
global?: Record<string, any>;
|
||
|
PageHeader?: { back: string };
|
||
|
Icon?: Record<string, any>;
|
||
3 years ago
|
Text?: {
|
||
|
edit?: any;
|
||
|
copy?: any;
|
||
|
copied?: any;
|
||
|
expand?: any;
|
||
|
};
|
||
5 years ago
|
Form?: {
|
||
4 years ago
|
optional?: string;
|
||
5 years ago
|
defaultValidateMessages: ValidateMessages;
|
||
|
};
|
||
4 years ago
|
Image?: {
|
||
|
preview: string;
|
||
|
};
|
||
2 years ago
|
QRCode?: {
|
||
|
expired: string;
|
||
|
refresh: string;
|
||
|
};
|
||
7 years ago
|
}
|
||
|
|
||
8 years ago
|
export interface LocaleProviderProps {
|
||
7 years ago
|
locale: Locale;
|
||
6 years ago
|
children?: React.ReactNode;
|
||
2 years ago
|
/** @internal */
|
||
5 years ago
|
_ANT_MARK__?: string;
|
||
8 years ago
|
}
|
||
|
|
||
2 years ago
|
const LocaleProvider: React.FC<LocaleProviderProps> = (props) => {
|
||
2 years ago
|
const { locale = {} as Locale, children, _ANT_MARK__ } = props;
|
||
5 years ago
|
|
||
2 years ago
|
if (process.env.NODE_ENV !== 'production') {
|
||
3 years ago
|
warning(
|
||
2 years ago
|
_ANT_MARK__ === ANT_MARK,
|
||
5 years ago
|
'LocaleProvider',
|
||
|
'`LocaleProvider` is deprecated. Please use `locale` with `ConfigProvider` instead: http://u.ant.design/locale',
|
||
|
);
|
||
7 years ago
|
}
|
||
|
|
||
2 years ago
|
React.useEffect(() => {
|
||
|
changeConfirmLocale(locale && locale.Modal);
|
||
|
return () => {
|
||
|
changeConfirmLocale();
|
||
|
};
|
||
|
}, [locale]);
|
||
4 years ago
|
|
||
2 years ago
|
const getMemoizedContextValue = React.useMemo<LocaleContextProps>(
|
||
|
() => ({ ...locale, exist: true }),
|
||
|
[locale],
|
||
|
);
|
||
9 years ago
|
|
||
2 years ago
|
return (
|
||
|
<LocaleContext.Provider value={getMemoizedContextValue}>{children}</LocaleContext.Provider>
|
||
|
);
|
||
|
};
|
||
3 years ago
|
|
||
2 years ago
|
export default LocaleProvider;
|