diff options
author | 2022-03-30 21:47:45 +0200 | |
---|---|---|
committer | 2022-05-16 00:54:57 +0200 | |
commit | 85d91c64b5b3ec31df8acecd68a1fa6a68d57ff9 (patch) | |
tree | 277ab45a66a1c74e2d0a885c8a354aea27128d12 /packages/renderer/src/components/locationBar | |
parent | feat(main): Translation hot reloading during development (diff) | |
download | sophie-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/locationBar')
3 files changed, 23 insertions, 9 deletions
diff --git a/packages/renderer/src/components/locationBar/ExtraButtons.tsx b/packages/renderer/src/components/locationBar/ExtraButtons.tsx index 4eaee29..1755495 100644 --- a/packages/renderer/src/components/locationBar/ExtraButtons.tsx +++ b/packages/renderer/src/components/locationBar/ExtraButtons.tsx | |||
@@ -23,6 +23,7 @@ import Box from '@mui/material/Box'; | |||
23 | import IconButton from '@mui/material/IconButton'; | 23 | import IconButton from '@mui/material/IconButton'; |
24 | import { observer } from 'mobx-react-lite'; | 24 | import { observer } from 'mobx-react-lite'; |
25 | import React from 'react'; | 25 | import React from 'react'; |
26 | import { useTranslation } from 'react-i18next'; | ||
26 | 27 | ||
27 | import type Service from '../../stores/Service'; | 28 | import type Service from '../../stores/Service'; |
28 | 29 | ||
@@ -31,6 +32,10 @@ function ExtraButtons({ | |||
31 | }: { | 32 | }: { |
32 | service: Service | undefined; | 33 | service: Service | undefined; |
33 | }): JSX.Element { | 34 | }): JSX.Element { |
35 | const { t } = useTranslation(undefined, { | ||
36 | keyPrefix: 'toolbar', | ||
37 | }); | ||
38 | |||
34 | return ( | 39 | return ( |
35 | <Box | 40 | <Box |
36 | sx={{ | 41 | sx={{ |
@@ -39,7 +44,7 @@ function ExtraButtons({ | |||
39 | }} | 44 | }} |
40 | > | 45 | > |
41 | <IconButton | 46 | <IconButton |
42 | aria-label="Open in browser" | 47 | aria-label={t('openInBrowser')} |
43 | disabled={service?.currentUrl === undefined} | 48 | disabled={service?.currentUrl === undefined} |
44 | onClick={() => service?.openCurrentURLInExternalBrowser()} | 49 | onClick={() => service?.openCurrentURLInExternalBrowser()} |
45 | > | 50 | > |
diff --git a/packages/renderer/src/components/locationBar/NavigationButtons.tsx b/packages/renderer/src/components/locationBar/NavigationButtons.tsx index 9995a21..219ed90 100644 --- a/packages/renderer/src/components/locationBar/NavigationButtons.tsx +++ b/packages/renderer/src/components/locationBar/NavigationButtons.tsx | |||
@@ -28,6 +28,7 @@ import Box from '@mui/material/Box'; | |||
28 | import IconButton from '@mui/material/IconButton'; | 28 | import IconButton from '@mui/material/IconButton'; |
29 | import { observer } from 'mobx-react-lite'; | 29 | import { observer } from 'mobx-react-lite'; |
30 | import React from 'react'; | 30 | import React from 'react'; |
31 | import { useTranslation } from 'react-i18next'; | ||
31 | 32 | ||
32 | import type Service from '../../stores/Service'; | 33 | import type Service from '../../stores/Service'; |
33 | 34 | ||
@@ -36,6 +37,9 @@ function NavigationButtons({ | |||
36 | }: { | 37 | }: { |
37 | service: Service | undefined; | 38 | service: Service | undefined; |
38 | }): JSX.Element { | 39 | }): JSX.Element { |
40 | const { t } = useTranslation(undefined, { | ||
41 | keyPrefix: 'toolbar', | ||
42 | }); | ||
39 | const { direction } = useTheme(); | 43 | const { direction } = useTheme(); |
40 | 44 | ||
41 | return ( | 45 | return ( |
@@ -46,26 +50,26 @@ function NavigationButtons({ | |||
46 | }} | 50 | }} |
47 | > | 51 | > |
48 | <IconButton | 52 | <IconButton |
49 | aria-label="Back" | 53 | aria-label={t('back')} |
50 | disabled={service === undefined || !service.canGoBack} | 54 | disabled={service === undefined || !service.canGoBack} |
51 | onClick={() => service?.goBack()} | 55 | onClick={() => service?.goBack()} |
52 | > | 56 | > |
53 | {direction === 'ltr' ? <IconArrowBack /> : <IconArrowForward />} | 57 | {direction === 'ltr' ? <IconArrowBack /> : <IconArrowForward />} |
54 | </IconButton> | 58 | </IconButton> |
55 | <IconButton | 59 | <IconButton |
56 | aria-label="Forward" | 60 | aria-label={t('forward')} |
57 | disabled={service === undefined || !service.canGoForward} | 61 | disabled={service === undefined || !service.canGoForward} |
58 | onClick={() => service?.goForward()} | 62 | onClick={() => service?.goForward()} |
59 | > | 63 | > |
60 | {direction === 'ltr' ? <IconArrowForward /> : <IconArrowBack />} | 64 | {direction === 'ltr' ? <IconArrowForward /> : <IconArrowBack />} |
61 | </IconButton> | 65 | </IconButton> |
62 | {service?.loading ?? false ? ( | 66 | {service?.loading ?? false ? ( |
63 | <IconButton aria-label="Stop" onClick={() => service?.stop()}> | 67 | <IconButton aria-label={t('stop')} onClick={() => service?.stop()}> |
64 | <IconStop /> | 68 | <IconStop /> |
65 | </IconButton> | 69 | </IconButton> |
66 | ) : ( | 70 | ) : ( |
67 | <IconButton | 71 | <IconButton |
68 | aria-label="Refresh" | 72 | aria-label={t('reload')} |
69 | disabled={service === undefined} | 73 | disabled={service === undefined} |
70 | onClick={(event) => service?.reload(event.shiftKey)} | 74 | onClick={(event) => service?.reload(event.shiftKey)} |
71 | > | 75 | > |
@@ -73,7 +77,7 @@ function NavigationButtons({ | |||
73 | </IconButton> | 77 | </IconButton> |
74 | )} | 78 | )} |
75 | <IconButton | 79 | <IconButton |
76 | aria-label="Home" | 80 | aria-label={t('home')} |
77 | disabled={service === undefined} | 81 | disabled={service === undefined} |
78 | onClick={() => service?.goHome()} | 82 | onClick={() => service?.goHome()} |
79 | > | 83 | > |
diff --git a/packages/renderer/src/components/locationBar/SecurityLabel.tsx b/packages/renderer/src/components/locationBar/SecurityLabel.tsx index 6e27e6b..d9dff86 100644 --- a/packages/renderer/src/components/locationBar/SecurityLabel.tsx +++ b/packages/renderer/src/components/locationBar/SecurityLabel.tsx | |||
@@ -24,6 +24,7 @@ import IconGlobe from '@mui/icons-material/Public'; | |||
24 | import IconWarning from '@mui/icons-material/Warning'; | 24 | import IconWarning from '@mui/icons-material/Warning'; |
25 | import { styled } from '@mui/material/styles'; | 25 | import { styled } from '@mui/material/styles'; |
26 | import React from 'react'; | 26 | import React from 'react'; |
27 | import { useTranslation } from 'react-i18next'; | ||
27 | 28 | ||
28 | import LocationInputAdornment from './LocationInputAdornment'; | 29 | import LocationInputAdornment from './LocationInputAdornment'; |
29 | import getAlertColor from './getAlertColor'; | 30 | import getAlertColor from './getAlertColor'; |
@@ -60,6 +61,10 @@ export default function SecurityLabel({ | |||
60 | changed: boolean; | 61 | changed: boolean; |
61 | position: 'start' | 'end'; | 62 | position: 'start' | 'end'; |
62 | }): JSX.Element { | 63 | }): JSX.Element { |
64 | const { t } = useTranslation(undefined, { | ||
65 | keyPrefix: 'securityLabel', | ||
66 | }); | ||
67 | |||
63 | const { type } = splitResult; | 68 | const { type } = splitResult; |
64 | if (changed || type === 'empty') { | 69 | if (changed || type === 'empty') { |
65 | return ( | 70 | return ( |
@@ -75,14 +80,14 @@ export default function SecurityLabel({ | |||
75 | <SecurityLabelRoot | 80 | <SecurityLabelRoot |
76 | alert={false} | 81 | alert={false} |
77 | position={position} | 82 | position={position} |
78 | aria-label="Secure connection" | 83 | aria-label={t('secureConnection')} |
79 | > | 84 | > |
80 | <IconHttps fontSize="small" /> | 85 | <IconHttps fontSize="small" /> |
81 | </SecurityLabelRoot> | 86 | </SecurityLabelRoot> |
82 | ) : ( | 87 | ) : ( |
83 | <SecurityLabelRoot alert position={position}> | 88 | <SecurityLabelRoot alert position={position}> |
84 | <IconHttp fontSize="small" /> | 89 | <IconHttp fontSize="small" /> |
85 | <SecurityLabelText>Not secure</SecurityLabelText> | 90 | <SecurityLabelText>{t('notSecureConnection')}</SecurityLabelText> |
86 | </SecurityLabelRoot> | 91 | </SecurityLabelRoot> |
87 | ); | 92 | ); |
88 | } | 93 | } |
@@ -90,7 +95,7 @@ export default function SecurityLabel({ | |||
90 | return ( | 95 | return ( |
91 | <SecurityLabelRoot alert position={position}> | 96 | <SecurityLabelRoot alert position={position}> |
92 | <IconWarning fontSize="small" /> | 97 | <IconWarning fontSize="small" /> |
93 | <SecurityLabelText>Unknown site</SecurityLabelText> | 98 | <SecurityLabelText>{t('unknownSite')}</SecurityLabelText> |
94 | </SecurityLabelRoot> | 99 | </SecurityLabelRoot> |
95 | ); | 100 | ); |
96 | default: | 101 | default: |