import type { App, VNode, PropType } from 'vue'; import { provide, defineComponent, reactive, watch } from 'vue'; import PropTypes from '../_util/vue-types'; import type { ModalLocale } from '../modal/locale'; import warning from '../_util/warning'; import { withInstall } from '../_util/type'; import type { ValidateMessages } from '../form/interface'; import type { TransferLocale } from '../transfer'; import type { PickerLocale as DatePickerLocale } from '../date-picker/generatePicker'; import type { PaginationLocale } from '../pagination/Pagination'; import type { TableLocale } from '../table/interface'; interface TransferLocaleForEmpty { description: string; } export interface Locale { locale: string; Pagination?: PaginationLocale; Table?: TableLocale; Popconfirm?: Record; Upload?: Record; Form?: { optional?: string; defaultValidateMessages: ValidateMessages; }; Image?: { preview: string; }; DatePicker?: DatePickerLocale; TimePicker?: Record; Calendar?: Record; Modal?: ModalLocale; Transfer?: Partial; Select?: Record; Empty?: TransferLocaleForEmpty; global?: Record; PageHeader?: { back: string }; Icon?: Record; Text?: Record; } export interface LocaleProviderProps { locale: Locale; children?: VNode | VNode[]; ANT_MARK__?: string; } export const ANT_MARK = 'internalMark'; const LocaleProvider = defineComponent({ name: 'ALocaleProvider', props: { locale: { type: Object as PropType, }, ANT_MARK__: PropTypes.string, }, setup(props, { slots }) { warning( props.ANT_MARK__ === ANT_MARK, 'LocaleProvider', '`LocaleProvider` is deprecated. Please use `locale` with `ConfigProvider` instead', ); const state = reactive({ antLocale: { ...props.locale, exist: true, }, ANT_MARK__: ANT_MARK, }); provide('localeData', state); watch( () => props.locale, () => { state.antLocale = { ...props.locale, exist: true, } as any; }, { immediate: true }, ); return () => { return slots.default?.(); }; }, }); /* istanbul ignore next */ LocaleProvider.install = function (app: App) { app.component(LocaleProvider.name, LocaleProvider); return app; }; export default withInstall(LocaleProvider);