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.
45 lines
1.1 KiB
45 lines
1.1 KiB
7 years ago
|
|
||
7 years ago
|
import PropTypes from '../_util/vue-types'
|
||
|
|
||
|
export default {
|
||
|
props: {
|
||
|
componentName: PropTypes.string,
|
||
|
defaultLocale: PropTypes.oneOfType([
|
||
|
PropTypes.object,
|
||
|
PropTypes.func,
|
||
|
]),
|
||
|
children: PropTypes.func,
|
||
|
},
|
||
|
inject: {
|
||
7 years ago
|
localeData: { default: {}},
|
||
7 years ago
|
},
|
||
|
methods: {
|
||
|
getLocale () {
|
||
7 years ago
|
const { componentName, defaultLocale } = this
|
||
7 years ago
|
const { antLocale } = this.localeData
|
||
7 years ago
|
const localeFromContext = antLocale && antLocale[componentName]
|
||
|
return {
|
||
|
...(typeof defaultLocale === 'function' ? defaultLocale() : defaultLocale),
|
||
|
...(localeFromContext || {}),
|
||
|
}
|
||
|
},
|
||
|
|
||
|
getLocaleCode () {
|
||
7 years ago
|
const { antLocale } = this.localeData
|
||
7 years ago
|
const localeCode = antLocale && antLocale.locale
|
||
|
// Had use LocaleProvide but didn't set locale
|
||
|
if (antLocale && antLocale.exist && !localeCode) {
|
||
|
return 'en-us'
|
||
|
}
|
||
|
return localeCode
|
||
|
},
|
||
|
},
|
||
|
|
||
|
render () {
|
||
7 years ago
|
const { $scopedSlots } = this
|
||
|
const children = this.children || $scopedSlots.default
|
||
|
return children(this.getLocale(), this.getLocaleCode())
|
||
7 years ago
|
},
|
||
|
}
|
||
|
|