2018-03-19 10:16:27 +08:00
|
|
|
|
2018-02-23 16:14:59 +08:00
|
|
|
import PropTypes from '../_util/vue-types'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
componentName: PropTypes.string,
|
|
|
|
defaultLocale: PropTypes.oneOfType([
|
|
|
|
PropTypes.object,
|
|
|
|
PropTypes.func,
|
|
|
|
]),
|
|
|
|
children: PropTypes.func,
|
|
|
|
},
|
|
|
|
inject: {
|
2018-03-15 22:21:25 +08:00
|
|
|
localeData: { default: {}},
|
2018-02-23 16:14:59 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getLocale () {
|
2018-02-24 18:12:24 +08:00
|
|
|
const { componentName, defaultLocale } = this
|
2018-03-15 22:21:25 +08:00
|
|
|
const { antLocale } = this.localeData
|
2018-02-23 16:14:59 +08:00
|
|
|
const localeFromContext = antLocale && antLocale[componentName]
|
|
|
|
return {
|
|
|
|
...(typeof defaultLocale === 'function' ? defaultLocale() : defaultLocale),
|
|
|
|
...(localeFromContext || {}),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getLocaleCode () {
|
2018-03-15 22:21:25 +08:00
|
|
|
const { antLocale } = this.localeData
|
2018-02-23 16:14:59 +08:00
|
|
|
const localeCode = antLocale && antLocale.locale
|
|
|
|
// Had use LocaleProvide but didn't set locale
|
|
|
|
if (antLocale && antLocale.exist && !localeCode) {
|
|
|
|
return 'en-us'
|
|
|
|
}
|
|
|
|
return localeCode
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
render () {
|
2018-03-15 21:40:34 +08:00
|
|
|
const { $scopedSlots } = this
|
|
|
|
const children = this.children || $scopedSlots.default
|
|
|
|
return children(this.getLocale(), this.getLocaleCode())
|
2018-02-23 16:14:59 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|