diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-03-30 01:36:22 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-05-16 00:54:57 +0200 |
commit | 7af01713180066b6dc1061dae930840e48c60fec (patch) | |
tree | 604a52eb8f167caf3400dad7589aaa5be2d06c8d /packages/main/src/infrastructure/electron | |
parent | feat: Add custom menubar (diff) | |
download | sophie-7af01713180066b6dc1061dae930840e48c60fec.tar.gz sophie-7af01713180066b6dc1061dae930840e48c60fec.tar.zst sophie-7af01713180066b6dc1061dae930840e48c60fec.zip |
feat(main): Add localization support
Add i18next with a custom backend to the main process to load
localization from file.
Missing localizations are written to a missing localizations file in
debug mode, but silently fall back in production mode.
We will also need to add a custom backend for the renderer process that
communicates with the main process.
(i18next-fs-electron-backend is not applicable here, because we need
localizations both in the main and renderer processes.)
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/main/src/infrastructure/electron')
-rw-r--r-- | packages/main/src/infrastructure/electron/impl/setApplicationMenu.ts | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/packages/main/src/infrastructure/electron/impl/setApplicationMenu.ts b/packages/main/src/infrastructure/electron/impl/setApplicationMenu.ts index 5166719..49bfbfd 100644 --- a/packages/main/src/infrastructure/electron/impl/setApplicationMenu.ts +++ b/packages/main/src/infrastructure/electron/impl/setApplicationMenu.ts | |||
@@ -30,6 +30,12 @@ export default function setApplicationMenu( | |||
30 | isMac: boolean, | 30 | isMac: boolean, |
31 | ): void { | 31 | ): void { |
32 | const dispose = autorun(() => { | 32 | const dispose = autorun(() => { |
33 | const translation = store.useTranslation(); | ||
34 | if (!translation.ready) { | ||
35 | return; | ||
36 | } | ||
37 | const { t } = translation; | ||
38 | |||
33 | const { settings, shared, visibleService } = store; | 39 | const { settings, shared, visibleService } = store; |
34 | const { showLocationBar, selectedService } = settings; | 40 | const { showLocationBar, selectedService } = settings; |
35 | const { canSwitchServices, services } = shared; | 41 | const { canSwitchServices, services } = shared; |
@@ -42,7 +48,7 @@ export default function setApplicationMenu( | |||
42 | role: 'viewMenu', | 48 | role: 'viewMenu', |
43 | submenu: [ | 49 | submenu: [ |
44 | { | 50 | { |
45 | label: 'Show Location Bar', | 51 | label: t<string>('menu.view.showLocationBar'), |
46 | accelerator: 'CommandOrControl+Shift+L', | 52 | accelerator: 'CommandOrControl+Shift+L', |
47 | type: 'checkbox', | 53 | type: 'checkbox', |
48 | checked: showLocationBar, | 54 | checked: showLocationBar, |
@@ -52,7 +58,7 @@ export default function setApplicationMenu( | |||
52 | }, | 58 | }, |
53 | { type: 'separator' }, | 59 | { type: 'separator' }, |
54 | { | 60 | { |
55 | label: 'Reload', | 61 | label: t<string>('menu.view.reload'), |
56 | accelerator: 'CommandOrControl+R', | 62 | accelerator: 'CommandOrControl+R', |
57 | enabled: selectedService !== undefined, | 63 | enabled: selectedService !== undefined, |
58 | click() { | 64 | click() { |
@@ -60,7 +66,7 @@ export default function setApplicationMenu( | |||
60 | }, | 66 | }, |
61 | }, | 67 | }, |
62 | { | 68 | { |
63 | label: 'Force Reload', | 69 | label: t<string>('menu.view.forceReload'), |
64 | accelerator: 'CommandOrControl+Shift+R', | 70 | accelerator: 'CommandOrControl+Shift+R', |
65 | enabled: selectedService !== undefined, | 71 | enabled: selectedService !== undefined, |
66 | click() { | 72 | click() { |
@@ -68,7 +74,7 @@ export default function setApplicationMenu( | |||
68 | }, | 74 | }, |
69 | }, | 75 | }, |
70 | { | 76 | { |
71 | label: 'Toggle Developer Tools', | 77 | label: t<string>('menu.view.toggleDeveloperTools'), |
72 | accelerator: 'CommandOrControl+Shift+I', | 78 | accelerator: 'CommandOrControl+Shift+I', |
73 | enabled: visibleService !== undefined, | 79 | enabled: visibleService !== undefined, |
74 | click() { | 80 | click() { |
@@ -80,12 +86,15 @@ export default function setApplicationMenu( | |||
80 | ? ([ | 86 | ? ([ |
81 | { | 87 | { |
82 | role: 'forceReload', | 88 | role: 'forceReload', |
83 | label: 'Reload Sophie', | 89 | label: t<string>('menu.view.reloadSophie'), |
84 | accelerator: 'CommandOrControl+Shift+Alt+R', | 90 | accelerator: 'CommandOrControl+Shift+Alt+R', |
85 | }, | 91 | }, |
86 | { | 92 | { |
87 | role: 'toggleDevTools', | 93 | role: 'toggleDevTools', |
88 | label: 'Toggle Sophie Developer Tools', | 94 | label: t<string>( |
95 | 'menu.view.toggleSophieDeveloperTools', | ||
96 | 'Toggle Sophie Developer Tools', | ||
97 | ), | ||
89 | accelerator: 'CommandOrControl+Shift+Alt+I', | 98 | accelerator: 'CommandOrControl+Shift+Alt+I', |
90 | }, | 99 | }, |
91 | { type: 'separator' }, | 100 | { type: 'separator' }, |
@@ -95,10 +104,10 @@ export default function setApplicationMenu( | |||
95 | ], | 104 | ], |
96 | }, | 105 | }, |
97 | { | 106 | { |
98 | label: 'Services', | 107 | label: t<string>('menu.servicesMenu'), |
99 | submenu: [ | 108 | submenu: [ |
100 | { | 109 | { |
101 | label: 'Next Service', | 110 | label: t<string>('menu.services.nextService'), |
102 | accelerator: 'CommandOrControl+Tab', | 111 | accelerator: 'CommandOrControl+Tab', |
103 | enabled: canSwitchServices, | 112 | enabled: canSwitchServices, |
104 | click() { | 113 | click() { |
@@ -106,7 +115,7 @@ export default function setApplicationMenu( | |||
106 | }, | 115 | }, |
107 | }, | 116 | }, |
108 | { | 117 | { |
109 | label: 'Previous Service', | 118 | label: t<string>('menu.services.previousService'), |
110 | accelerator: 'CommandOrControl+Shift+Tab', | 119 | accelerator: 'CommandOrControl+Shift+Tab', |
111 | enabled: canSwitchServices, | 120 | enabled: canSwitchServices, |
112 | click() { | 121 | click() { |
@@ -140,7 +149,7 @@ export default function setApplicationMenu( | |||
140 | role: 'help', | 149 | role: 'help', |
141 | submenu: [ | 150 | submenu: [ |
142 | { | 151 | { |
143 | label: 'Gitlab', | 152 | label: t<string>('menu.help.gitlab'), |
144 | click() { | 153 | click() { |
145 | store.openWebpageInBrowser(); | 154 | store.openWebpageInBrowser(); |
146 | }, | 155 | }, |