1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-06-19 09:32:18 +02:00

localize menu options

This commit is contained in:
Kyle Spearrin 2018-02-09 00:21:00 -05:00
parent c76b4821c6
commit 092bdb5e07
4 changed files with 76 additions and 62 deletions

View File

@ -606,5 +606,20 @@
}, },
"logOut": { "logOut": {
"message": "Log Out" "message": "Log Out"
},
"addNewLogin": {
"message": "Add New Login"
},
"addNewItem": {
"message": "Add New Item"
},
"addNewFolder": {
"message": "Add New Folder"
},
"view": {
"message": "View"
},
"account": {
"message": "Account"
} }
} }

View File

@ -15,12 +15,15 @@ if (watch) {
} }
const i18nService = new I18nService('en', './locales/'); const i18nService = new I18nService('en', './locales/');
i18nService.init().then(() => { });
const windowMain = new WindowMain(dev); const windowMain = new WindowMain(dev);
const messagingMain = new MessagingMain(); const messagingMain = new MessagingMain();
const menuMain = new MenuMain(windowMain); const menuMain = new MenuMain(windowMain, i18nService);
messagingMain.init();
menuMain.init();
windowMain.init(); windowMain.init();
messagingMain.init();
i18nService.init().then(() => {
menuMain.init();
}, (e: any) => {
console.log(e);
});

View File

@ -8,95 +8,115 @@ import {
import { WindowMain } from './window.main'; import { WindowMain } from './window.main';
import { I18nService } from '../services/i18n.service';
export class MenuMain { export class MenuMain {
constructor(private windowMain: WindowMain) { } constructor(private windowMain: WindowMain, private i18nService: I18nService) { }
init() { init() {
const self = this; const self = this;
const template: MenuItemConstructorOptions[] = [ const template: MenuItemConstructorOptions[] = [
{
label: 'bitwarden'
},
{ {
label: 'File', label: 'File',
submenu: [ submenu: [
{ {
label: 'New Item', label: this.i18nService.t('addNewLogin'),
click() {
self.send('newLogin');
},
accelerator: 'CmdOrCtrl+N'
},
{
label: this.i18nService.t('addNewItem'),
submenu: [ submenu: [
{ {
label: 'New Login', label: this.i18nService.t('typeLogin'),
click() { click() {
self.send('newLogin'); self.send('newLogin');
} }
}, },
{ {
label: 'New Card', label: this.i18nService.t('typeCard'),
click() { click() {
self.send('newCard'); self.send('newCard');
} }
}, },
{ {
label: 'New Identity', label: this.i18nService.t('typeIdentity'),
click() { click() {
self.send('newIdentity'); self.send('newIdentity');
} }
}, },
{ {
label: 'New Secure Note', label: this.i18nService.t('typeSecureNote'),
click() { click() {
self.send('newSecureNote'); self.send('newSecureNote');
} }
} }
] ]
}, },
{ type: 'separator' },
{ {
label: 'New Login', label: this.i18nService.t('addNewFolder'),
click() {
self.send('newLogin');
}
},
{
label: 'New Folder',
click() { click() {
self.send('newFolder'); 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: [ submenu: [
{ role: 'undo' }, { role: 'undo' },
{ role: 'redo' }, { role: 'redo' },
{ type: 'separator' }, { type: 'separator' },
{ role: 'selectall' },
{ role: 'cut' }, { role: 'cut' },
{ role: 'copy' }, { role: 'copy' },
{ role: 'paste' }, { role: 'paste' },
{ role: 'pasteandmatchstyle' },
{ role: 'delete' },
{ role: 'selectall' }
] ]
}, },
{ {
label: 'View', label: this.i18nService.t('view'),
submenu: [ submenu: [
{ role: 'reload' }, { role: 'reload' },
{ role: 'forcereload' }, { role: 'forcereload' },
{ role: 'toggledevtools' }, { role: 'toggledevtools' },
{ type: 'separator' }, { type: 'separator' },
{ role: 'resetzoom' }, {
{ role: 'zoomin' }, role: 'resetzoom',
{ role: 'zoomout' }, accelerator: 'CmdOrCtrl+0' },
{
role: 'zoomin',
accelerator: 'CmdOrCtrl+=' },
{
role: 'zoomout',
accelerator: 'CmdOrCtrl+-'
},
{ type: 'separator' }, { type: 'separator' },
{ role: 'togglefullscreen' } { role: 'togglefullscreen' }
] ]
}, },
{ {
label: 'Account', label: this.i18nService.t('account'),
submenu: [ submenu: [
{ {
label: 'Log Out', label: this.i18nService.t('logOut'),
click() { click() {
self.send('confirmLogout'); self.send('confirmLogout');
} }
@ -122,19 +142,8 @@ export class MenuMain {
]; ];
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
template[0].submenu = [ template[0].label = app.getName();
{ (template[0].submenu as MenuItemConstructorOptions[]).concat([
label: 'Settings',
click() {
self.send('openSettings');
}
},
{
label: 'Lock',
click() {
self.send('lockApp');
}
},
{ type: 'separator' }, { type: 'separator' },
{ role: 'about' }, { role: 'about' },
{ type: 'separator' }, { type: 'separator' },
@ -145,7 +154,7 @@ export class MenuMain {
{ role: 'unhide' }, { role: 'unhide' },
{ type: 'separator' }, { type: 'separator' },
{ role: 'quit' } { role: 'quit' }
]; ]);
// Window menu // Window menu
template[4].submenu = [ template[4].submenu = [
@ -155,21 +164,6 @@ export class MenuMain {
{ type: 'separator' }, { type: 'separator' },
{ role: 'front' } { role: 'front' }
] ]
} else {
template[0].submenu = [
{
label: 'Settings',
click() {
self.send('openSettings');
}
},
{
label: 'Lock',
click() {
self.send('lockApp');
}
},
];
} }
const menu = Menu.buildFromTemplate(template); const menu = Menu.buildFromTemplate(template);

View File

@ -1,3 +1,4 @@
import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import { I18nService as I18nServiceAbstraction } from 'jslib/abstractions/i18n.service'; 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<any> { private loadMessages(locale: string, messagesObj: any): Promise<any> {
const formattedLocale = locale.replace('-', '_'); const formattedLocale = locale.replace('-', '_');
const filePath = path.join(__dirname, this.localesDirectory + '/' + formattedLocale + '/messages.json'); 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) { for (const prop in locales) {
if (!locales.hasOwnProperty(prop)) { if (!locales.hasOwnProperty(prop)) {
continue; continue;