ant-design/components/modal/locale.tsx

41 lines
887 B
TypeScript
Raw Normal View History

import defaultLocale from '../locale/en_US';
2017-07-31 01:50:46 +08:00
export interface ModalLocale {
okText: string;
cancelText: string;
justOkText: string;
}
let runtimeLocale: ModalLocale = {
2020-03-11 14:56:01 +08:00
...(defaultLocale.Modal as ModalLocale),
};
let localeList: ModalLocale[] = [];
const generateLocale = () =>
localeList.reduce(
(merged, locale) => ({ ...merged, ...locale }),
defaultLocale.Modal as ModalLocale,
);
2017-07-31 01:50:46 +08:00
export function changeConfirmLocale(newLocale?: ModalLocale) {
if (newLocale) {
const cloneLocale = { ...newLocale };
localeList.push(cloneLocale);
runtimeLocale = generateLocale();
return () => {
localeList = localeList.filter((locale) => locale !== cloneLocale);
runtimeLocale = generateLocale();
};
}
runtimeLocale = {
...(defaultLocale.Modal as ModalLocale),
};
}
2016-05-12 15:11:25 +08:00
export function getConfirmLocale() {
return runtimeLocale;
}