ant-design/components/modal/locale.ts
lijianan 2b629ef391
type: rm useless type of reducer (#49555)
* type: rm useless type of reducer

* Update components/_util/ActionButton.tsx

Signed-off-by: lijianan <574980606@qq.com>

---------

Signed-off-by: lijianan <574980606@qq.com>
2024-06-22 23:57:39 +08:00

41 lines
886 B
TypeScript

import defaultLocale from '../locale/en_US';
export interface ModalLocale {
okText: string;
cancelText: string;
justOkText: string;
}
let runtimeLocale: ModalLocale = {
...(defaultLocale.Modal as ModalLocale),
};
let localeList: ModalLocale[] = [];
const generateLocale = () =>
localeList.reduce<ModalLocale>(
(merged, locale) => ({ ...merged, ...locale }),
defaultLocale.Modal!,
);
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),
};
}
export function getConfirmLocale() {
return runtimeLocale;
}