2022-10-26 14:38:54 +08:00
|
|
|
import defaultLocale from '../locale/en_US';
|
2017-09-26 23:12:47 +08:00
|
|
|
|
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),
|
2017-07-03 16:57:11 +08:00
|
|
|
};
|
2016-05-12 13:25:00 +08:00
|
|
|
|
2023-07-26 18:56:27 +08:00
|
|
|
let localeList: ModalLocale[] = [];
|
|
|
|
|
|
|
|
const generateLocale = () =>
|
2024-06-22 23:57:39 +08:00
|
|
|
localeList.reduce<ModalLocale>(
|
2023-07-26 18:56:27 +08:00
|
|
|
(merged, locale) => ({ ...merged, ...locale }),
|
2024-06-22 23:57:39 +08:00
|
|
|
defaultLocale.Modal!,
|
2023-07-26 18:56:27 +08:00
|
|
|
);
|
|
|
|
|
2017-07-31 01:50:46 +08:00
|
|
|
export function changeConfirmLocale(newLocale?: ModalLocale) {
|
2016-05-12 13:25:00 +08:00
|
|
|
if (newLocale) {
|
2023-07-26 18:56:27 +08:00
|
|
|
const cloneLocale = { ...newLocale };
|
|
|
|
localeList.push(cloneLocale);
|
|
|
|
runtimeLocale = generateLocale();
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
localeList = localeList.filter((locale) => locale !== cloneLocale);
|
|
|
|
runtimeLocale = generateLocale();
|
2017-07-03 16:57:11 +08:00
|
|
|
};
|
2016-05-12 13:25:00 +08:00
|
|
|
}
|
2023-07-26 18:56:27 +08:00
|
|
|
|
|
|
|
runtimeLocale = {
|
|
|
|
...(defaultLocale.Modal as ModalLocale),
|
|
|
|
};
|
2016-05-12 13:25:00 +08:00
|
|
|
}
|
|
|
|
|
2016-05-12 15:11:25 +08:00
|
|
|
export function getConfirmLocale() {
|
2016-05-12 13:25:00 +08:00
|
|
|
return runtimeLocale;
|
|
|
|
}
|