From 3d90479cbab3c73d67e457e9f51fec51b4edf8d0 Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Sun, 30 Jan 2022 17:13:53 +0000 Subject: [PATCH] Forgot to add locale *I'm really starting to hate typescript* --- src/main/base/app.ts | 9 ++++++--- src/main/base/win.ts | 16 ++++++++++++++-- src/main/index.ts | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/base/app.ts b/src/main/base/app.ts index 870797f4..fb72d057 100644 --- a/src/main/base/app.ts +++ b/src/main/base/app.ts @@ -14,6 +14,7 @@ export class AppEvents { private store: any = undefined; private win: any = undefined; private tray: any = undefined; + private i18n: any = undefined; constructor(store: any) { this.store = store @@ -112,8 +113,9 @@ export class AppEvents { console.log('[AppEvents] App ready'); } - public bwCreated(win: Electron.BrowserWindow) { + public bwCreated(win: Electron.BrowserWindow, i18n: any) { this.win = win + this.i18n = i18n electron.app.on('open-url', (event, url) => { event.preventDefault() @@ -226,6 +228,7 @@ export class AppEvents { height: 20 }), } + console.log(this.i18n) this.tray = new electron.Tray(process.platform === 'win32' ? icons.win32 : (process.platform === 'darwin' ? icons.darwin : icons.linux)) this.tray.setToolTip(electron.app.getName()) @@ -266,7 +269,7 @@ export class AppEvents { const menu = electron.Menu.buildFromTemplate([ { - label: (visible ? 'Minimize to Tray' : `Show ${electron.app.getName()}`), + label: (visible ? this.i18n['action.tray.minimize'] : `${this.i18n['action.tray.show']} ${electron.app.getName()}`), click: () => { if (this.win) { if (visible) { @@ -278,7 +281,7 @@ export class AppEvents { } }, { - label: 'Quit', + label: this.i18n['action.tray.quit'], click: () => { electron.app.quit() } diff --git a/src/main/base/win.ts b/src/main/base/win.ts index 8a228d31..31b34442 100644 --- a/src/main/base/win.ts +++ b/src/main/base/win.ts @@ -19,6 +19,7 @@ export class Win { private app: any | undefined = null; private store: any | undefined = null; private devMode: boolean = !electron.app.isPackaged; + public i18n: any = {}; constructor(app: electron.App, store: any) { this.app = app; @@ -288,18 +289,29 @@ export class Win { event.returnValue = process.platform; }); + let i18nBase = fs.readFileSync(path.join(__dirname, "../../src/i18n/en_US.jsonc"), "utf8"); + i18nBase = jsonc.parse(i18nBase) + try { + let i18n = fs.readFileSync(path.join(__dirname, `../../src/i18n/${this.store.general.language}.jsonc`), "utf8"); + i18n = jsonc.parse(i18n) + this.i18n = Object.assign(i18nBase, i18n) + } catch (e) { + console.error(e); + } + electron.ipcMain.on("get-i18n", (event, key) => { let i18nBase = fs.readFileSync(path.join(__dirname, "../../src/i18n/en_US.jsonc"), "utf8"); i18nBase = jsonc.parse(i18nBase) try { let i18n = fs.readFileSync(path.join(__dirname, `../../src/i18n/${key}.jsonc`), "utf8"); i18n = jsonc.parse(i18n) - Object.assign(i18nBase, i18n) + this.i18n = Object.assign(i18nBase, i18n) } catch (e) { console.error(e); event.returnValue = e; } - + + this.i18n = i18nBase; event.returnValue = i18nBase; }); diff --git a/src/main/index.ts b/src/main/index.ts index 59196a9f..e6557a4c 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -32,7 +32,7 @@ electron.app.on('ready', () => { electron.components.whenReady().then(async () => { win = await Cider.createWindow() - App.bwCreated(win); + App.bwCreated(win, Cider.i18n); /// please dont change this for plugins to get proper and fully initialized Win objects plug.callPlugins('onReady', win); win.on("ready-to-show", () => {