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.
ant-design-vue/components/locale-provider/index.jsx

73 lines
1.4 KiB

7 years ago
import PropTypes from '../_util/vue-types'
import * as moment from 'moment'
7 years ago
import interopDefault from '../_util/interopDefault'
import { changeConfirmLocale } from '../modal/locale'
7 years ago
// 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;
// }
function setMomentLocale (locale) {
if (locale && locale.locale) {
7 years ago
interopDefault(moment).locale(locale.locale)
7 years ago
} else {
7 years ago
interopDefault(moment).locale('en')
7 years ago
}
}
export default {
name: 'ALocaleProvider',
7 years ago
props: {
locale: PropTypes.object.def({}),
},
7 years ago
data () {
7 years ago
return {
antLocale: {
...this.locale,
exist: true,
},
}
},
7 years ago
provide () {
return {
localeData: this.$data,
}
},
7 years ago
watch: {
locale (val) {
7 years ago
this.antLocale = {
...this.locale,
exist: true,
}
7 years ago
setMomentLocale(val)
},
},
beforeMount () {
const { locale } = this
setMomentLocale(locale)
changeConfirmLocale(locale && locale.Modal)
7 years ago
},
updated () {
const { locale } = this
changeConfirmLocale(locale && locale.Modal)
7 years ago
},
beforeDestroy () {
changeConfirmLocale()
7 years ago
},
render () {
return this.$slots.default[0]
7 years ago
},
}