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