aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/src/components/NewWindowBanner.tsx
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-03-30 21:47:45 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-05-16 00:54:57 +0200
commit85d91c64b5b3ec31df8acecd68a1fa6a68d57ff9 (patch)
tree277ab45a66a1c74e2d0a885c8a354aea27128d12 /packages/renderer/src/components/NewWindowBanner.tsx
parentfeat(main): Translation hot reloading during development (diff)
downloadsophie-85d91c64b5b3ec31df8acecd68a1fa6a68d57ff9.tar.gz
sophie-85d91c64b5b3ec31df8acecd68a1fa6a68d57ff9.tar.zst
sophie-85d91c64b5b3ec31df8acecd68a1fa6a68d57ff9.zip
feat(renderer): Renderer translations
Add react-i18n to make us able to use i18next translations in the renderer process just like we do in the main process. Translations are hot-reloaded automatically. Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/renderer/src/components/NewWindowBanner.tsx')
-rw-r--r--packages/renderer/src/components/NewWindowBanner.tsx25
1 files changed, 16 insertions, 9 deletions
diff --git a/packages/renderer/src/components/NewWindowBanner.tsx b/packages/renderer/src/components/NewWindowBanner.tsx
index a49b4b1..9aa6121 100644
--- a/packages/renderer/src/components/NewWindowBanner.tsx
+++ b/packages/renderer/src/components/NewWindowBanner.tsx
@@ -23,6 +23,7 @@ import IconOpenInNew from '@mui/icons-material/OpenInNew';
23import Button from '@mui/material/Button'; 23import Button from '@mui/material/Button';
24import { observer } from 'mobx-react-lite'; 24import { observer } from 'mobx-react-lite';
25import React from 'react'; 25import React from 'react';
26import { Trans, useTranslation } from 'react-i18next';
26 27
27import type Service from '../stores/Service'; 28import type Service from '../stores/Service';
28 29
@@ -33,6 +34,10 @@ function NewWindowBanner({
33}: { 34}: {
34 service: Service | undefined; 35 service: Service | undefined;
35}): JSX.Element | null { 36}): JSX.Element | null {
37 const { t } = useTranslation(undefined, {
38 keyPrefix: 'banner.newWindow',
39 });
40
36 if (service === undefined) { 41 if (service === undefined) {
37 // eslint-disable-next-line unicorn/no-null -- React requires `null` to skip rendering. 42 // eslint-disable-next-line unicorn/no-null -- React requires `null` to skip rendering.
38 return null; 43 return null;
@@ -63,7 +68,7 @@ function NewWindowBanner({
63 color="inherit" 68 color="inherit"
64 size="small" 69 size="small"
65 > 70 >
66 Follow link in this window 71 {t('followLink')}
67 </Button> 72 </Button>
68 <Button 73 <Button
69 onClick={() => service.openPopupInExternalBrowser(url)} 74 onClick={() => service.openPopupInExternalBrowser(url)}
@@ -71,7 +76,7 @@ function NewWindowBanner({
71 size="small" 76 size="small"
72 startIcon={<IconOpenInBrowser />} 77 startIcon={<IconOpenInBrowser />}
73 > 78 >
74 Open in browser 79 {t('openInExternalBrowser')}
75 </Button> 80 </Button>
76 {count > 1 && ( 81 {count > 1 && (
77 <> 82 <>
@@ -81,27 +86,29 @@ function NewWindowBanner({
81 size="small" 86 size="small"
82 startIcon={<IconOpenInBrowser />} 87 startIcon={<IconOpenInBrowser />}
83 > 88 >
84 Open all 89 {t('openAllInExternalBrowser')}
85 </Button> 90 </Button>
86 <Button 91 <Button
87 onClick={() => service.dismissPopup(url)} 92 onClick={() => service.dismissPopup(url)}
88 color="inherit" 93 color="inherit"
89 size="small" 94 size="small"
90 > 95 >
91 Ignore 96 {t('dismiss')}
92 </Button> 97 </Button>
93 </> 98 </>
94 )} 99 )}
95 </> 100 </>
96 } 101 }
97 > 102 >
98 {name} wants to open <b>{url}</b>{' '}
99 {count === 1 ? ( 103 {count === 1 ? (
100 <>in a new window</> 104 <Trans i18nKey="messageSingleLink" t={t}>
105 {{ name }} wants to open <strong>{{ url }}</strong> in a new window
106 </Trans>
101 ) : ( 107 ) : (
102 <> 108 <Trans i18nKey="messageMultipleLinks" count={count - 1} t={t}>
103 and <b>{count}</b> other links in new windows 109 {{ name }} wants to open <strong>{{ url }}</strong> and{' '}
104 </> 110 <strong>{{ count: count - 1 }}</strong> other links in new windows
111 </Trans>
105 )} 112 )}
106 </NotificationBanner> 113 </NotificationBanner>
107 ); 114 );