mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 11:39:28 +08:00
9088414d54
* fix: Modal.confirm locale setting were reset * chore: add test case * test: update test case * fix: lint * fix: format --------- Co-authored-by: 二货机器人 <smith3816@gmail.com>
41 lines
887 B
TypeScript
41 lines
887 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(
|
|
(merged, locale) => ({ ...merged, ...locale }),
|
|
defaultLocale.Modal as ModalLocale,
|
|
);
|
|
|
|
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;
|
|
}
|