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": {
"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/');
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);
});

View File

@ -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);

View File

@ -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<any> {
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;