ant-design-vue/components/_util/getLocale.js

31 lines
874 B
JavaScript
Raw Normal View History

2019-01-12 03:33:27 +00:00
export function getComponentLocale(props, context, componentName, getDefaultLocale) {
let locale = {};
2017-12-07 10:33:33 +00:00
if (context && context.antLocale && context.antLocale[componentName]) {
2019-01-12 03:33:27 +00:00
locale = context.antLocale[componentName];
2017-12-07 10:33:33 +00:00
} else {
2019-01-12 03:33:27 +00:00
const defaultLocale = getDefaultLocale();
2017-12-07 10:33:33 +00:00
// TODO: make default lang of antd be English
// https://github.com/ant-design/ant-design/issues/6334
2019-01-12 03:33:27 +00:00
locale = defaultLocale.default || defaultLocale;
2017-12-07 10:33:33 +00:00
}
const result = {
...locale,
...props.locale,
2019-01-12 03:33:27 +00:00
};
2017-12-07 10:33:33 +00:00
result.lang = {
...locale.lang,
...props.locale.lang,
2019-01-12 03:33:27 +00:00
};
return result;
2017-12-07 10:33:33 +00:00
}
2019-01-12 03:33:27 +00:00
export function getLocaleCode(context) {
const localeCode = context.antLocale && context.antLocale.locale;
2017-12-07 10:33:33 +00:00
// Had use LocaleProvide but didn't set locale
if (context.antLocale && context.antLocale.exist && !localeCode) {
2019-01-12 03:33:27 +00:00
return 'zh-cn';
2017-12-07 10:33:33 +00:00
}
2019-01-12 03:33:27 +00:00
return localeCode;
2017-12-07 10:33:33 +00:00
}