diff options
author | 2022-03-30 21:47:45 +0200 | |
---|---|---|
committer | 2022-05-16 00:54:57 +0200 | |
commit | 85d91c64b5b3ec31df8acecd68a1fa6a68d57ff9 (patch) | |
tree | 277ab45a66a1c74e2d0a885c8a354aea27128d12 /packages/main/src/infrastructure/electron/impl | |
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/main/src/infrastructure/electron/impl')
-rw-r--r-- | packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts | 25 | ||||
-rw-r--r-- | packages/main/src/infrastructure/electron/impl/setApplicationMenu.ts | 5 |
2 files changed, 26 insertions, 4 deletions
diff --git a/packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts b/packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts index cff7957..6144d89 100644 --- a/packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts +++ b/packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts | |||
@@ -22,6 +22,7 @@ import { | |||
22 | Action, | 22 | Action, |
23 | MainToRendererIpcMessage, | 23 | MainToRendererIpcMessage, |
24 | RendererToMainIpcMessage, | 24 | RendererToMainIpcMessage, |
25 | Translation, | ||
25 | } from '@sophie/shared'; | 26 | } from '@sophie/shared'; |
26 | import { BrowserWindow, ipcMain, IpcMainEvent } from 'electron'; | 27 | import { BrowserWindow, ipcMain, IpcMainEvent } from 'electron'; |
27 | import type { IJsonPatch } from 'mobx-state-tree'; | 28 | import type { IJsonPatch } from 'mobx-state-tree'; |
@@ -96,6 +97,24 @@ export default class ElectronMainWindow implements MainWindow { | |||
96 | return this.bridge.snapshot; | 97 | return this.bridge.snapshot; |
97 | }); | 98 | }); |
98 | 99 | ||
100 | ipcMain.handle( | ||
101 | RendererToMainIpcMessage.GetTranslation, | ||
102 | (event, translation) => { | ||
103 | const { id } = event.sender; | ||
104 | if (id !== webContents.id) { | ||
105 | log.warn( | ||
106 | 'Unexpected', | ||
107 | RendererToMainIpcMessage.GetTranslation, | ||
108 | 'from webContents', | ||
109 | id, | ||
110 | ); | ||
111 | throw new Error('Invalid IPC call'); | ||
112 | } | ||
113 | const { language, namespace } = Translation.parse(translation); | ||
114 | return store.getTranslation(language, namespace); | ||
115 | }, | ||
116 | ); | ||
117 | |||
99 | this.bridge = new RendererBridge(store, (patch) => { | 118 | this.bridge = new RendererBridge(store, (patch) => { |
100 | webContents.send(MainToRendererIpcMessage.SharedStorePatch, patch); | 119 | webContents.send(MainToRendererIpcMessage.SharedStorePatch, patch); |
101 | }); | 120 | }); |
@@ -142,6 +161,12 @@ export default class ElectronMainWindow implements MainWindow { | |||
142 | ); | 161 | ); |
143 | } | 162 | } |
144 | 163 | ||
164 | reloadTranslations(): void { | ||
165 | this.browserWindow.webContents.send( | ||
166 | MainToRendererIpcMessage.ReloadTranslations, | ||
167 | ); | ||
168 | } | ||
169 | |||
145 | dispose() { | 170 | dispose() { |
146 | this.bridge.dispose(); | 171 | this.bridge.dispose(); |
147 | this.browserWindow.destroy(); | 172 | this.browserWindow.destroy(); |
diff --git a/packages/main/src/infrastructure/electron/impl/setApplicationMenu.ts b/packages/main/src/infrastructure/electron/impl/setApplicationMenu.ts index 49bfbfd..8e10383 100644 --- a/packages/main/src/infrastructure/electron/impl/setApplicationMenu.ts +++ b/packages/main/src/infrastructure/electron/impl/setApplicationMenu.ts | |||
@@ -91,10 +91,7 @@ export default function setApplicationMenu( | |||
91 | }, | 91 | }, |
92 | { | 92 | { |
93 | role: 'toggleDevTools', | 93 | role: 'toggleDevTools', |
94 | label: t<string>( | 94 | label: t<string>('menu.view.toggleSophieDeveloperTools'), |
95 | 'menu.view.toggleSophieDeveloperTools', | ||
96 | 'Toggle Sophie Developer Tools', | ||
97 | ), | ||
98 | accelerator: 'CommandOrControl+Shift+Alt+I', | 95 | accelerator: 'CommandOrControl+Shift+Alt+I', |
99 | }, | 96 | }, |
100 | { type: 'separator' }, | 97 | { type: 'separator' }, |