diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index b0b6f38f..332bf40f 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -606,5 +606,20 @@ }, "logOut": { "message": "Log Out" + }, + "addNewLogin": { + "message": "Add New Login" + }, + "addNewItem": { + "message": "Add New Item" + }, + "addNewFolder": { + "message": "Add New Folder" + }, + "view": { + "message": "View" + }, + "account": { + "message": "Account" } } diff --git a/src/main.ts b/src/main.ts index def0d90e..548662fe 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,12 +15,15 @@ if (watch) { } const i18nService = new I18nService('en', './locales/'); -i18nService.init().then(() => { }); - const windowMain = new WindowMain(dev); const messagingMain = new MessagingMain(); -const menuMain = new MenuMain(windowMain); +const menuMain = new MenuMain(windowMain, i18nService); -messagingMain.init(); -menuMain.init(); windowMain.init(); +messagingMain.init(); + +i18nService.init().then(() => { + menuMain.init(); +}, (e: any) => { + console.log(e); +}); diff --git a/src/main/menu.main.ts b/src/main/menu.main.ts index 617dfd7d..589c42ae 100644 --- a/src/main/menu.main.ts +++ b/src/main/menu.main.ts @@ -8,95 +8,115 @@ import { import { WindowMain } from './window.main'; +import { I18nService } from '../services/i18n.service'; + export class MenuMain { - constructor(private windowMain: WindowMain) { } + constructor(private windowMain: WindowMain, private i18nService: I18nService) { } init() { const self = this; const template: MenuItemConstructorOptions[] = [ - { - label: 'bitwarden' - }, { label: 'File', submenu: [ { - label: 'New Item', + label: this.i18nService.t('addNewLogin'), + click() { + self.send('newLogin'); + }, + accelerator: 'CmdOrCtrl+N' + }, + { + label: this.i18nService.t('addNewItem'), submenu: [ { - label: 'New Login', + label: this.i18nService.t('typeLogin'), click() { self.send('newLogin'); } }, { - label: 'New Card', + label: this.i18nService.t('typeCard'), click() { self.send('newCard'); } }, { - label: 'New Identity', + label: this.i18nService.t('typeIdentity'), click() { self.send('newIdentity'); } }, { - label: 'New Secure Note', + label: this.i18nService.t('typeSecureNote'), click() { self.send('newSecureNote'); } } ] }, + { type: 'separator' }, { - label: 'New Login', - click() { - self.send('newLogin'); - } - }, - { - label: 'New Folder', + label: this.i18nService.t('addNewFolder'), click() { self.send('newFolder'); } - } + }, + { type: 'separator' }, + { + label: this.i18nService.t('settings'), + click() { + self.send('openSettings'); + } + }, + { + label: 'Lock', + click() { + self.send('lockApp'); + }, + accelerator: 'CmdOrCtrl+L' + }, ] }, { - label: 'Edit', + label: this.i18nService.t('edit'), submenu: [ { role: 'undo' }, { role: 'redo' }, { type: 'separator' }, + { role: 'selectall' }, { role: 'cut' }, { role: 'copy' }, { role: 'paste' }, - { role: 'pasteandmatchstyle' }, - { role: 'delete' }, - { role: 'selectall' } ] }, { - label: 'View', + label: this.i18nService.t('view'), submenu: [ { role: 'reload' }, { role: 'forcereload' }, { role: 'toggledevtools' }, { type: 'separator' }, - { role: 'resetzoom' }, - { role: 'zoomin' }, - { role: 'zoomout' }, + { + role: 'resetzoom', + accelerator: 'CmdOrCtrl+0' }, + { + role: 'zoomin', + accelerator: 'CmdOrCtrl+=' }, + { + role: 'zoomout', + accelerator: 'CmdOrCtrl+-' + }, { type: 'separator' }, { role: 'togglefullscreen' } ] }, { - label: 'Account', + label: this.i18nService.t('account'), submenu: [ { - label: 'Log Out', + label: this.i18nService.t('logOut'), click() { self.send('confirmLogout'); } @@ -122,19 +142,8 @@ export class MenuMain { ]; if (process.platform === 'darwin') { - template[0].submenu = [ - { - label: 'Settings', - click() { - self.send('openSettings'); - } - }, - { - label: 'Lock', - click() { - self.send('lockApp'); - } - }, + template[0].label = app.getName(); + (template[0].submenu as MenuItemConstructorOptions[]).concat([ { type: 'separator' }, { role: 'about' }, { type: 'separator' }, @@ -145,7 +154,7 @@ export class MenuMain { { role: 'unhide' }, { type: 'separator' }, { role: 'quit' } - ]; + ]); // Window menu template[4].submenu = [ @@ -155,21 +164,6 @@ export class MenuMain { { type: 'separator' }, { role: 'front' } ] - } else { - template[0].submenu = [ - { - label: 'Settings', - click() { - self.send('openSettings'); - } - }, - { - label: 'Lock', - click() { - self.send('lockApp'); - } - }, - ]; } const menu = Menu.buildFromTemplate(template); diff --git a/src/services/i18n.service.ts b/src/services/i18n.service.ts index fadc58fa..62804d61 100644 --- a/src/services/i18n.service.ts +++ b/src/services/i18n.service.ts @@ -1,3 +1,4 @@ +import * as fs from 'fs'; import * as path from 'path'; import { I18nService as I18nServiceAbstraction } from 'jslib/abstractions/i18n.service'; @@ -73,7 +74,8 @@ export class I18nService implements I18nServiceAbstraction { private loadMessages(locale: string, messagesObj: any): Promise { const formattedLocale = locale.replace('-', '_'); const filePath = path.join(__dirname, this.localesDirectory + '/' + formattedLocale + '/messages.json'); - const locales = (window as any).require(filePath); + const localesJson = fs.readFileSync(filePath, 'utf8'); + const locales = JSON.parse(localesJson.replace(/^\uFEFF/, '')); // strip the BOM for (const prop in locales) { if (!locales.hasOwnProperty(prop)) { continue;