diff --git a/src/notifications/NotificationAction.tsx b/src/notifications/NotificationAction.tsx new file mode 100644 index 00000000..e4b24f0e --- /dev/null +++ b/src/notifications/NotificationAction.tsx @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2021 The Pybricks Authors + +// provides translation for notification text + +import { Replacements, useI18n } from '@shopify/react-i18n'; +import React from 'react'; +import { MessageId } from './i18n'; +import en from './i18n.en.json'; + +type OwnProps = { + messageId: MessageId; + replacements?: Replacements; +}; + +export default function NotificationAction(props: OwnProps): JSX.Element { + const [i18n] = useI18n({ + id: 'notification', + translations: { en }, + fallback: en, + }); + const { messageId, replacements } = props; + return <>{i18n.translate(messageId, replacements)}; +} diff --git a/src/notifications/Notification.tsx b/src/notifications/NotificationMessage.tsx similarity index 92% rename from src/notifications/Notification.tsx rename to src/notifications/NotificationMessage.tsx index fc49da35..d191526b 100644 --- a/src/notifications/Notification.tsx +++ b/src/notifications/NotificationMessage.tsx @@ -13,7 +13,7 @@ type OwnProps = { replacements?: Replacements; }; -export default function Notification(props: OwnProps): JSX.Element { +export default function NotificationMessage(props: OwnProps): JSX.Element { const [i18n] = useI18n({ id: 'notification', translations: { en }, diff --git a/src/notifications/sagas.ts b/src/notifications/sagas.ts index 5ecb6b8d..75297607 100644 --- a/src/notifications/sagas.ts +++ b/src/notifications/sagas.ts @@ -37,7 +37,8 @@ import { ServiceWorkerAction, ServiceWorkerActionType, } from '../service-worker/actions'; -import Notification from './Notification'; +import NotificationAction from './NotificationAction'; +import NotificationMessage from './NotificationMessage'; import UnexpectedErrorNotification from './UnexpectedErrorNotification'; import { NotificationActionType, NotificationAddAction } from './actions'; import { MessageId } from './i18n'; @@ -101,7 +102,7 @@ function dispatchAction( ): IActionProps { return { icon: icon, - text: React.createElement(Notification, { messageId }), + text: React.createElement(NotificationAction, { messageId }), onClick, }; } @@ -140,7 +141,10 @@ function* showSingleton( { intent: mapIntent(level), icon: mapIcon(level), - message: React.createElement(Notification, { messageId, replacements }), + message: React.createElement(NotificationMessage, { + messageId, + replacements, + }), timeout: 0, action, onDismiss, @@ -371,7 +375,7 @@ function* showNoUpdateInfo(action: AppDidCheckForUpdateAction): Generator { toaster.show({ intent: mapIntent(Level.Info), icon: mapIcon(Level.Info), - message: React.createElement(Notification, { + message: React.createElement(NotificationMessage, { messageId: MessageId.AppNoUpdateFound, replacements: { appName }, }),