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/LocaleReceiver.vue

44 lines
1022 B

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