diff --git a/packages/frontend/component/src/ui/notification/desktop/notification-card.tsx b/packages/frontend/component/src/ui/notification/desktop/notification-card.tsx index d8b57141e..2ab268dd5 100644 --- a/packages/frontend/component/src/ui/notification/desktop/notification-card.tsx +++ b/packages/frontend/component/src/ui/notification/desktop/notification-card.tsx @@ -55,7 +55,7 @@ export const DesktopNotificationCard = ({ {icon} ) : null} -
{title ?? errorTitle}
+
{title || errorTitle}
{action ? (
diff --git a/packages/frontend/component/src/ui/notification/mobile/notification-card.tsx b/packages/frontend/component/src/ui/notification/mobile/notification-card.tsx index c5c3649ea..d520ad4c6 100644 --- a/packages/frontend/component/src/ui/notification/mobile/notification-card.tsx +++ b/packages/frontend/component/src/ui/notification/mobile/notification-card.tsx @@ -1,3 +1,4 @@ +import { useI18n } from '@affine/i18n'; import { CloseIcon, InformationFillDuotoneIcon } from '@blocksuite/icons/rc'; import { useCallback, useState } from 'react'; @@ -16,7 +17,14 @@ export function MobileNotificationCard({ icon = , iconColor, onDismiss, + error, } = notification; + const t = useI18n(); + const errorI18nKey = error ? (`error.${error.name}` as const) : undefined; + const errorTitle = + errorI18nKey && errorI18nKey in t + ? t[errorI18nKey](error?.data) + : undefined; const [animated, setAnimated] = useState(false); const [showDetail, setShowDetail] = useState(false); @@ -43,7 +51,9 @@ export function MobileNotificationCard({ style={getCardVars(style, theme, iconColor)} > {icon} - {notification.title} + + {notification.title || errorTitle} +
); } @@ -62,7 +72,14 @@ const MobileNotifyDetail = ({ message, footer, action, + error, } = notification; + const t = useI18n(); + const errorI18nKey = error ? (`error.${error.name}` as const) : undefined; + const errorTitle = + errorI18nKey && errorI18nKey in t + ? t[errorI18nKey](error?.data) + : undefined; const handleOpenChange = useCallback( (open: boolean) => { @@ -91,7 +108,7 @@ const MobileNotifyDetail = ({
e.stopPropagation()}>
{icon} - {title} + {title || errorTitle} } />
{message}
diff --git a/packages/frontend/i18n/src/i18next.ts b/packages/frontend/i18n/src/i18next.ts index 6eac01e62..785495404 100644 --- a/packages/frontend/i18n/src/i18next.ts +++ b/packages/frontend/i18n/src/i18next.ts @@ -150,6 +150,16 @@ export function createI18nWrapper(getI18nFn: () => i18n) { return I18nMethod.t.bind(null, key); }, + has(self, key: string) { + if (key in self) { + return true; + } + const i18n = getI18nFn(); + if (i18n.exists(key)) { + return true; + } + return false; + }, }) as typeof I18nMethod & ReturnType & { [unknownKey: string]: () => string }; }