diff options
author | haraldox <hnaumann+github@gmail.com> | 2018-03-01 10:49:21 +0100 |
---|---|---|
committer | haraldox <hnaumann+github@gmail.com> | 2018-03-01 10:49:21 +0100 |
commit | aa655ac1a73c2a04feac232062a94b8a8385e75d (patch) | |
tree | 5cd44c1ca784d0b71711076b15ecef68d1955800 /src/lib | |
parent | Update changelog (diff) | |
download | ferdium-app-aa655ac1a73c2a04feac232062a94b8a8385e75d.tar.gz ferdium-app-aa655ac1a73c2a04feac232062a94b8a8385e75d.tar.zst ferdium-app-aa655ac1a73c2a04feac232062a94b8a8385e75d.zip |
ADD Franz-wide internationalization
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Menu.js | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/lib/Menu.js b/src/lib/Menu.js index 16e91374e..d94064ada 100644 --- a/src/lib/Menu.js +++ b/src/lib/Menu.js | |||
@@ -1,13 +1,21 @@ | |||
1 | import { remote, shell } from 'electron'; | 1 | import { remote, shell } from 'electron'; |
2 | import { autorun, computed, observable, toJS } from 'mobx'; | 2 | import { autorun, computed, observable, toJS } from 'mobx'; |
3 | import { defineMessages } from 'react-intl'; | ||
3 | 4 | ||
4 | import { isMac } from '../environment'; | 5 | import { isMac } from '../environment'; |
5 | 6 | ||
6 | const { app, Menu, dialog } = remote; | 7 | const { app, Menu, dialog } = remote; |
7 | 8 | ||
8 | const template = [ | 9 | const menuItems = defineMessages({ |
10 | edit: { | ||
11 | id: 'menu.edit', | ||
12 | defaultMessage: '!!!Edit', | ||
13 | }, | ||
14 | }); | ||
15 | |||
16 | const _makeTemplate = intl => [ | ||
9 | { | 17 | { |
10 | label: 'Edit', | 18 | label: intl.formatMessage(menuItems.edit), |
11 | submenu: [ | 19 | submenu: [ |
12 | { | 20 | { |
13 | role: 'undo', | 21 | role: 'undo', |
@@ -115,8 +123,6 @@ const template = [ | |||
115 | ]; | 123 | ]; |
116 | 124 | ||
117 | export default class FranzMenu { | 125 | export default class FranzMenu { |
118 | @observable tpl = template; | ||
119 | |||
120 | constructor(stores, actions) { | 126 | constructor(stores, actions) { |
121 | this.stores = stores; | 127 | this.stores = stores; |
122 | this.actions = actions; | 128 | this.actions = actions; |
@@ -124,8 +130,19 @@ export default class FranzMenu { | |||
124 | autorun(this._build.bind(this)); | 130 | autorun(this._build.bind(this)); |
125 | } | 131 | } |
126 | 132 | ||
133 | rebuild() { | ||
134 | this._build(); | ||
135 | } | ||
136 | |||
127 | _build() { | 137 | _build() { |
128 | const tpl = toJS(this.tpl); | 138 | // console.log(window.franz); |
139 | const serviceTpl = Object.assign([], this.serviceTpl); // need to clone object so we don't modify computed (cached) object | ||
140 | |||
141 | if (window.franz === undefined) { | ||
142 | return; | ||
143 | } | ||
144 | |||
145 | const tpl = _makeTemplate(window.franz.intl); | ||
129 | 146 | ||
130 | tpl[1].submenu.push({ | 147 | tpl[1].submenu.push({ |
131 | role: 'toggledevtools', | 148 | role: 'toggledevtools', |
@@ -232,8 +249,6 @@ export default class FranzMenu { | |||
232 | }); | 249 | }); |
233 | } | 250 | } |
234 | 251 | ||
235 | const serviceTpl = this.serviceTpl; | ||
236 | |||
237 | serviceTpl.unshift({ | 252 | serviceTpl.unshift({ |
238 | label: 'Add new Service', | 253 | label: 'Add new Service', |
239 | accelerator: 'CmdOrCtrl+N', | 254 | accelerator: 'CmdOrCtrl+N', |
@@ -245,7 +260,7 @@ export default class FranzMenu { | |||
245 | }); | 260 | }); |
246 | 261 | ||
247 | if (serviceTpl.length > 0) { | 262 | if (serviceTpl.length > 0) { |
248 | tpl[isMac ? 3 : 2].submenu = toJS(this.serviceTpl); | 263 | tpl[isMac ? 3 : 2].submenu = serviceTpl; |
249 | } | 264 | } |
250 | 265 | ||
251 | const menu = Menu.buildFromTemplate(tpl); | 266 | const menu = Menu.buildFromTemplate(tpl); |