2021-06-26 09:35:40 +08:00
|
|
|
import type { App, VNode, PropType } from 'vue';
|
2021-10-26 16:12:56 +08:00
|
|
|
import { provide, defineComponent, reactive, watch } from 'vue';
|
2019-01-12 11:33:27 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2021-06-26 09:35:40 +08:00
|
|
|
import type { ModalLocale } from '../modal/locale';
|
2020-03-07 19:45:13 +08:00
|
|
|
import warning from '../_util/warning';
|
2020-11-07 15:08:42 +08:00
|
|
|
import { withInstall } from '../_util/type';
|
2021-06-26 09:35:40 +08:00
|
|
|
import type { ValidateMessages } from '../form/interface';
|
2021-09-25 16:51:32 +08:00
|
|
|
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;
|
|
|
|
}
|
2020-08-15 15:33:47 +08:00
|
|
|
export interface Locale {
|
|
|
|
locale: string;
|
2021-09-25 16:51:32 +08:00
|
|
|
Pagination?: PaginationLocale;
|
|
|
|
Table?: TableLocale;
|
|
|
|
Popconfirm?: Record<string, any>;
|
|
|
|
Upload?: Record<string, any>;
|
2021-06-07 17:35:03 +08:00
|
|
|
Form?: {
|
|
|
|
optional?: string;
|
|
|
|
defaultValidateMessages: ValidateMessages;
|
|
|
|
};
|
|
|
|
Image?: {
|
|
|
|
preview: string;
|
|
|
|
};
|
2021-09-25 16:51:32 +08:00
|
|
|
DatePicker?: DatePickerLocale;
|
|
|
|
TimePicker?: Record<string, any>;
|
|
|
|
Calendar?: Record<string, any>;
|
|
|
|
Modal?: ModalLocale;
|
|
|
|
Transfer?: Partial<TransferLocale>;
|
|
|
|
Select?: Record<string, any>;
|
|
|
|
Empty?: TransferLocaleForEmpty;
|
|
|
|
global?: Record<string, any>;
|
|
|
|
PageHeader?: { back: string };
|
|
|
|
Icon?: Record<string, any>;
|
|
|
|
Text?: Record<string, any>;
|
2020-08-15 15:33:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface LocaleProviderProps {
|
|
|
|
locale: Locale;
|
|
|
|
children?: VNode | VNode[];
|
2020-10-13 18:04:02 +08:00
|
|
|
ANT_MARK__?: string;
|
2020-08-15 15:33:47 +08:00
|
|
|
}
|
|
|
|
|
2020-03-07 19:45:13 +08:00
|
|
|
export const ANT_MARK = 'internalMark';
|
2020-08-15 15:33:47 +08:00
|
|
|
|
|
|
|
const LocaleProvider = defineComponent({
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'ALocaleProvider',
|
2018-02-23 16:14:59 +08:00
|
|
|
props: {
|
2020-08-16 00:21:58 +08:00
|
|
|
locale: {
|
2020-10-13 17:46:52 +08:00
|
|
|
type: Object as PropType<Locale>,
|
2020-08-16 00:21:58 +08:00
|
|
|
},
|
2020-10-13 18:04:02 +08:00
|
|
|
ANT_MARK__: PropTypes.string,
|
2018-02-23 16:14:59 +08:00
|
|
|
},
|
2021-06-07 17:35:03 +08:00
|
|
|
setup(props, { slots }) {
|
2020-09-29 22:06:01 +08:00
|
|
|
warning(
|
2020-10-13 18:04:02 +08:00
|
|
|
props.ANT_MARK__ === ANT_MARK,
|
2020-09-29 22:06:01 +08:00
|
|
|
'LocaleProvider',
|
|
|
|
'`LocaleProvider` is deprecated. Please use `locale` with `ConfigProvider` instead',
|
|
|
|
);
|
2020-10-28 22:04:12 +08:00
|
|
|
const state = reactive({
|
2020-09-29 22:06:01 +08:00
|
|
|
antLocale: {
|
|
|
|
...props.locale,
|
|
|
|
exist: true,
|
|
|
|
},
|
2020-10-13 18:04:02 +08:00
|
|
|
ANT_MARK__: ANT_MARK,
|
2020-10-28 22:04:12 +08:00
|
|
|
});
|
|
|
|
provide('localeData', state);
|
2021-06-07 17:35:03 +08:00
|
|
|
watch(
|
|
|
|
() => props.locale,
|
2021-10-26 16:12:56 +08:00
|
|
|
() => {
|
2021-06-07 17:35:03 +08:00
|
|
|
state.antLocale = {
|
2021-09-25 16:51:32 +08:00
|
|
|
...props.locale,
|
2021-06-07 17:35:03 +08:00
|
|
|
exist: true,
|
2021-09-25 16:51:32 +08:00
|
|
|
} as any;
|
2021-06-07 17:35:03 +08:00
|
|
|
},
|
|
|
|
{ immediate: true },
|
|
|
|
);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
return slots.default?.();
|
|
|
|
};
|
2018-02-23 16:14:59 +08:00
|
|
|
},
|
2020-08-15 15:33:47 +08:00
|
|
|
});
|
2018-02-23 16:14:59 +08:00
|
|
|
|
2018-09-19 13:21:57 +08:00
|
|
|
/* istanbul ignore next */
|
2021-06-23 23:08:16 +08:00
|
|
|
LocaleProvider.install = function (app: App) {
|
2020-06-22 23:16:47 +08:00
|
|
|
app.component(LocaleProvider.name, LocaleProvider);
|
2020-10-13 19:14:56 +08:00
|
|
|
return app;
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-09-19 13:21:57 +08:00
|
|
|
|
2020-11-07 15:08:42 +08:00
|
|
|
export default withInstall(LocaleProvider);
|