1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-28 12:35:40 +01:00

i18n from main proc as well

This commit is contained in:
Kyle Spearrin 2018-01-24 16:02:18 -05:00
parent e42bf66b2f
commit c49ac847d6
3 changed files with 9 additions and 7 deletions

View File

@ -56,7 +56,7 @@ import {
webFrame.registerURLSchemeAsPrivileged('file'); webFrame.registerURLSchemeAsPrivileged('file');
const i18nService = new I18nService(window, './_locales'); const i18nService = new I18nService(window.navigator.language, './_locales');
const utilsService = new UtilsService(); const utilsService = new UtilsService();
const platformUtilsService = new DesktopPlatformUtilsService(); const platformUtilsService = new DesktopPlatformUtilsService();
const messagingService = new DesktopMessagingService(); const messagingService = new DesktopMessagingService();

View File

@ -1,4 +1,4 @@
import { app, BrowserWindow, screen, ipcMain } from 'electron'; import { app, BrowserWindow, ipcMain, screen } from 'electron';
import * as path from 'path'; import * as path from 'path';
import * as url from 'url'; import * as url from 'url';
/* /*
@ -26,6 +26,10 @@ ipcMain.on('keytar', async (event: any, message: any) => {
}); });
*/ */
import { I18nService } from './services/i18n.service';
const i18nService = new I18nService('en', './_locales/');
i18nService.init().then(() => { });
let win: BrowserWindow; let win: BrowserWindow;
const args = process.argv.slice(1); const args = process.argv.slice(1);
const watch = args.some((val) => val === '--watch'); const watch = args.some((val) => val === '--watch');

View File

@ -8,12 +8,10 @@ const SupportedLocales = [
export class I18nService { export class I18nService {
defaultMessages: any = {}; defaultMessages: any = {};
localeMessages: any = {}; localeMessages: any = {};
systemLanguage: string;
language: string; language: string;
inited: boolean; inited: boolean;
constructor(win: Window, private localesDirectory: string) { constructor(private systemLanguage: string, private localesDirectory: string) {
this.systemLanguage = win.navigator.language;
} }
async init(language?: string) { async init(language?: string) {
@ -39,10 +37,10 @@ export class I18nService {
} }
t(id: string): string { t(id: string): string {
return this.translation(id); return this.translate(id);
} }
translation(id: string): string { translate(id: string): string {
if (this.localeMessages.hasOwnProperty(id) && this.localeMessages[id]) { if (this.localeMessages.hasOwnProperty(id) && this.localeMessages[id]) {
return this.localeMessages[id]; return this.localeMessages[id];
} else if (this.defaultMessages.hasOwnProperty(id) && this.defaultMessages[id]) { } else if (this.defaultMessages.hasOwnProperty(id) && this.defaultMessages[id]) {