2019-01-12 11:33:27 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import * as moment from 'moment';
|
|
|
|
import interopDefault from '../_util/interopDefault';
|
|
|
|
import { changeConfirmLocale } from '../modal/locale';
|
2019-08-28 10:50:19 +08:00
|
|
|
import Base from '../base';
|
2020-03-07 19:45:13 +08:00
|
|
|
import warning from '../_util/warning';
|
2018-02-23 16:14:59 +08:00
|
|
|
// export interface Locale {
|
|
|
|
// locale: string;
|
|
|
|
// Pagination?: Object;
|
|
|
|
// DatePicker?: Object;
|
|
|
|
// TimePicker?: Object;
|
|
|
|
// Calendar?: Object;
|
|
|
|
// Table?: Object;
|
|
|
|
// Modal?: ModalLocale;
|
|
|
|
// Popconfirm?: Object;
|
|
|
|
// Transfer?: Object;
|
|
|
|
// Select?: Object;
|
|
|
|
// Upload?: Object;
|
|
|
|
// }
|
2020-03-07 19:45:13 +08:00
|
|
|
export const ANT_MARK = 'internalMark';
|
2019-01-12 11:33:27 +08:00
|
|
|
function setMomentLocale(locale) {
|
2018-02-23 16:14:59 +08:00
|
|
|
if (locale && locale.locale) {
|
2019-01-12 11:33:27 +08:00
|
|
|
interopDefault(moment).locale(locale.locale);
|
2018-02-23 16:14:59 +08:00
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
interopDefault(moment).locale('en');
|
2018-02-23 16:14:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 13:21:57 +08:00
|
|
|
const LocaleProvider = {
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'ALocaleProvider',
|
2018-02-23 16:14:59 +08:00
|
|
|
props: {
|
2020-03-07 19:45:13 +08:00
|
|
|
locale: PropTypes.object.def(() => ({})),
|
|
|
|
_ANT_MARK__: PropTypes.string,
|
2018-02-23 16:14:59 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
data() {
|
2020-03-07 19:45:13 +08:00
|
|
|
warning(
|
|
|
|
this._ANT_MARK__ === ANT_MARK,
|
|
|
|
'LocaleProvider',
|
|
|
|
'`LocaleProvider` is deprecated. Please use `locale` with `ConfigProvider` instead',
|
|
|
|
);
|
2018-02-23 16:14:59 +08:00
|
|
|
return {
|
|
|
|
antLocale: {
|
|
|
|
...this.locale,
|
|
|
|
exist: true,
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-02-23 16:14:59 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
provide() {
|
2018-03-15 22:21:25 +08:00
|
|
|
return {
|
|
|
|
localeData: this.$data,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-03-15 22:21:25 +08:00
|
|
|
},
|
2018-02-23 16:14:59 +08:00
|
|
|
watch: {
|
2019-01-12 11:33:27 +08:00
|
|
|
locale(val) {
|
2018-03-15 22:21:25 +08:00
|
|
|
this.antLocale = {
|
|
|
|
...this.locale,
|
|
|
|
exist: true,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2019-05-14 22:15:24 +08:00
|
|
|
setMomentLocale(val);
|
2020-03-07 19:45:13 +08:00
|
|
|
changeConfirmLocale(val && val.Modal);
|
2018-02-23 16:14:59 +08:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
created() {
|
|
|
|
const { locale } = this;
|
|
|
|
setMomentLocale(locale);
|
|
|
|
changeConfirmLocale(locale && locale.Modal);
|
2018-02-23 16:14:59 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
beforeDestroy() {
|
|
|
|
changeConfirmLocale();
|
2018-02-23 16:14:59 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
|
|
|
return this.$slots.default ? this.$slots.default[0] : null;
|
2018-02-23 16:14:59 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-02-23 16:14:59 +08:00
|
|
|
|
2018-09-19 13:21:57 +08:00
|
|
|
/* istanbul ignore next */
|
2019-01-12 11:33:27 +08:00
|
|
|
LocaleProvider.install = function(Vue) {
|
2019-08-28 10:50:19 +08:00
|
|
|
Vue.use(Base);
|
2019-01-12 11:33:27 +08:00
|
|
|
Vue.component(LocaleProvider.name, LocaleProvider);
|
|
|
|
};
|
2018-09-19 13:21:57 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
export default LocaleProvider;
|