2016-10-01 00:17:31 +08:00
|
|
|
import assign from 'object-assign';
|
|
|
|
|
2017-01-09 16:25:58 +08:00
|
|
|
export function getComponentLocale(props, context, componentName, getDefaultLocale) {
|
2017-06-02 16:11:30 +08:00
|
|
|
let locale: any = {};
|
|
|
|
if (context && context.antLocale && context.antLocale[componentName]) {
|
|
|
|
locale = context.antLocale[componentName];
|
|
|
|
} else {
|
|
|
|
const defaultLocale = getDefaultLocale();
|
|
|
|
// TODO: make default lang of antd be English
|
|
|
|
// https://github.com/ant-design/ant-design/issues/6334
|
|
|
|
locale = defaultLocale.default || defaultLocale;
|
|
|
|
}
|
2016-10-20 14:48:13 +08:00
|
|
|
|
2016-10-01 00:17:31 +08:00
|
|
|
const result = assign({}, locale, props.locale);
|
|
|
|
result.lang = assign({}, locale.lang, props.locale.lang);
|
|
|
|
return result;
|
|
|
|
}
|
2017-01-09 16:25:58 +08:00
|
|
|
|
|
|
|
export function getLocaleCode(context) {
|
|
|
|
const localeCode = context.antLocale && context.antLocale.locale;
|
|
|
|
// Had use LocaleProvide but didn't set locale
|
|
|
|
if (context.antLocale && context.antLocale.exist && !localeCode) {
|
|
|
|
return 'zh-cn';
|
|
|
|
}
|
|
|
|
return localeCode;
|
|
|
|
}
|