forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocaleReceiver.jsx
47 lines (43 loc) · 1.36 KB
/
LocaleReceiver.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { inject } from 'vue';
import PropTypes from '../_util/vue-types';
import defaultLocaleData from './default';
export default {
name: 'LocaleReceiver',
props: {
componentName: PropTypes.string.def('global'),
defaultLocale: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
children: PropTypes.func,
},
setup() {
return {
localeData: inject('localeData', {}),
};
},
methods: {
getLocale() {
const { componentName, defaultLocale } = this;
const locale = defaultLocale || defaultLocaleData[componentName || 'global'];
const { antLocale } = this.localeData;
const localeFromContext = componentName && antLocale ? antLocale[componentName] : {};
return {
...(typeof locale === 'function' ? locale() : locale),
...(localeFromContext || {}),
};
},
getLocaleCode() {
const { antLocale } = this.localeData;
const localeCode = antLocale && antLocale.locale;
// Had use LocaleProvide but didn't set locale
if (antLocale && antLocale.exist && !localeCode) {
return defaultLocaleData.locale;
}
return localeCode;
},
},
render() {
const { $slots } = this;
const children = this.children || $slots.default;
const { antLocale } = this.localeData;
return children?.(this.getLocale(), this.getLocaleCode(), antLocale);
},
};