ant-design-vue/components/locale-provider/LocaleReceiver.vue

44 lines
1022 B
Vue
Raw Normal View History

2018-02-23 08:14:59 +00:00
<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 () {
2018-02-24 10:12:24 +00:00
const { componentName, defaultLocale } = this
2018-02-23 08:14:59 +00:00
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>