refactor: support i18n

This commit is contained in:
mlogclub
2026-05-25 12:06:15 +08:00
parent 309ac1fe9e
commit 988f55c80d
179 changed files with 10968 additions and 3763 deletions
+7 -9
View File
@@ -18,6 +18,7 @@ import {
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
import { useI18n } from "@/i18n/provider"
type ConfirmOptions = {
title?: ReactNode
@@ -39,14 +40,11 @@ const ConfirmContext = createContext<ConfirmContextValue | null>(null)
const defaultState: ConfirmState = {
open: false,
title: "请确认操作",
description: "确认后将继续执行当前操作。",
confirmText: "确认",
cancelText: "取消",
variant: "default",
}
export function ConfirmProvider({ children }: { children: ReactNode }) {
const t = useI18n()
const [state, setState] = useState<ConfirmState>(defaultState)
const resolverRef = useRef<((value: boolean) => void) | null>(null)
@@ -63,17 +61,17 @@ export function ConfirmProvider({ children }: { children: ReactNode }) {
setState({
open: true,
title: options.title ?? defaultState.title,
description: options.description ?? defaultState.description,
confirmText: options.confirmText ?? defaultState.confirmText,
cancelText: options.cancelText ?? defaultState.cancelText,
title: options.title ?? t("confirm.title"),
description: options.description ?? t("confirm.description"),
confirmText: options.confirmText ?? t("confirm.confirm"),
cancelText: options.cancelText ?? t("confirm.cancel"),
variant: options.variant ?? defaultState.variant,
})
return new Promise<boolean>((resolve) => {
resolverRef.current = resolve
})
}, [])
}, [t])
return (
<ConfirmContext.Provider value={{ confirm }}>