ant-design/components/locale-provider/index.tsx

80 lines
2.2 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
import { ValidateMessages } from 'rc-field-form/lib/interface';
import devWarning from '../_util/devWarning';
2020-03-11 14:56:01 +08:00
import { ModalLocale, changeConfirmLocale } from '../modal/locale';
import { TransferLocale as TransferLocaleForEmpty } from '../empty';
import { PaginationLocale } from '../pagination/Pagination';
import { TableLocale } from '../table/interface';
import { PopconfirmLocale } from '../popconfirm';
import { UploadLocale } from '../upload/interface';
import { TransferLocale } from '../transfer';
import { PickerLocale as DatePickerLocale } from '../date-picker/generatePicker';
import LocaleContext from './context';
2020-03-11 14:56:01 +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;
DatePicker?: DatePickerLocale;
2018-01-13 17:53:25 +08:00
TimePicker?: Object;
Calendar?: Object;
2020-03-11 14:56:01 +08:00
Table?: TableLocale;
2018-01-13 17:53:25 +08:00
Modal?: ModalLocale;
2020-03-11 14:56:01 +08:00
Popconfirm?: PopconfirmLocale;
Transfer?: Partial<TransferLocale>;
2018-01-13 17:53:25 +08:00
Select?: Object;
2020-03-11 14:56:01 +08:00
Upload?: UploadLocale;
Empty?: TransferLocaleForEmpty;
global?: Object;
PageHeader?: Object;
Icon?: Object;
Text?: Object;
Form?: {
defaultValidateMessages: ValidateMessages;
};
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;
_ANT_MARK__?: string;
2016-08-02 16:10:26 +08:00
}
export default class LocaleProvider extends React.Component<LocaleProviderProps, any> {
2018-01-13 17:53:25 +08:00
static defaultProps = {
locale: {},
};
constructor(props: LocaleProviderProps) {
super(props);
changeConfirmLocale(props.locale && props.locale.Modal);
devWarning(
props._ANT_MARK__ === ANT_MARK,
'LocaleProvider',
'`LocaleProvider` is deprecated. Please use `locale` with `ConfigProvider` instead: http://u.ant.design/locale',
);
}
componentDidUpdate(prevProps: LocaleProviderProps) {
2018-01-13 17:53:25 +08:00
const { locale } = this.props;
if (prevProps.locale !== locale) {
2019-09-16 11:23:26 +08:00
changeConfirmLocale(locale && locale.Modal);
2018-01-13 17:53:25 +08:00
}
}
2018-01-13 17:53:25 +08:00
componentWillUnmount() {
changeConfirmLocale();
}
2016-03-03 16:28:02 +08:00
render() {
const { locale, children } = this.props;
return (
<LocaleContext.Provider value={{ ...locale, exist: true }}>{children}</LocaleContext.Provider>
);
2016-03-03 16:28:02 +08:00
}
}