diff --git a/.gitignore b/.gitignore index 98a5c7d..46803bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ # Webpack -app/renderer/build -app/main/build +app/build # Logs logs diff --git a/app/lib/i18n/de-AT.json b/app/lib/i18n/de-AT.json new file mode 100644 index 0000000..bcdd74d --- /dev/null +++ b/app/lib/i18n/de-AT.json @@ -0,0 +1,24 @@ +{ + "about": "Über", + "check": "Check", + "check for updates": "Auf Updates überprüfen...", + "checksum match": "Übereinstimmung", + "checksum mismatch": "Die Checksums stimmen nicht überein", + "checksum fail": "Fehler - Hast du versucht einen Ordner hinzuzufügen?", + "choose file": "Datei wählen...", + "copy": "Kopieren", + "cut": "Ausschneiden", + "drop file": "Datei hier ablegen", + "edit": "Bearbeiten", + "help": "Hilfe", + "hide others": "Andere ausblenden", + "hide": "Verstecken", + "learn more": "Erfahre mehr", + "open logs": "Öffne Logs", + "paste": "Einfügen", + "quit": "Beenden", + "unhide": "Alles anzeigen", + "update available": "Update verfügbar", + "update error": "Fehler beim Suchen nach Updates", + "update latest": "Deine Version ist aktuell" +} diff --git a/app/lib/i18n/de-CH.json b/app/lib/i18n/de-CH.json new file mode 100644 index 0000000..bcdd74d --- /dev/null +++ b/app/lib/i18n/de-CH.json @@ -0,0 +1,24 @@ +{ + "about": "Über", + "check": "Check", + "check for updates": "Auf Updates überprüfen...", + "checksum match": "Übereinstimmung", + "checksum mismatch": "Die Checksums stimmen nicht überein", + "checksum fail": "Fehler - Hast du versucht einen Ordner hinzuzufügen?", + "choose file": "Datei wählen...", + "copy": "Kopieren", + "cut": "Ausschneiden", + "drop file": "Datei hier ablegen", + "edit": "Bearbeiten", + "help": "Hilfe", + "hide others": "Andere ausblenden", + "hide": "Verstecken", + "learn more": "Erfahre mehr", + "open logs": "Öffne Logs", + "paste": "Einfügen", + "quit": "Beenden", + "unhide": "Alles anzeigen", + "update available": "Update verfügbar", + "update error": "Fehler beim Suchen nach Updates", + "update latest": "Deine Version ist aktuell" +} diff --git a/app/lib/i18n/de-DE.json b/app/lib/i18n/de-DE.json new file mode 100644 index 0000000..bcdd74d --- /dev/null +++ b/app/lib/i18n/de-DE.json @@ -0,0 +1,24 @@ +{ + "about": "Über", + "check": "Check", + "check for updates": "Auf Updates überprüfen...", + "checksum match": "Übereinstimmung", + "checksum mismatch": "Die Checksums stimmen nicht überein", + "checksum fail": "Fehler - Hast du versucht einen Ordner hinzuzufügen?", + "choose file": "Datei wählen...", + "copy": "Kopieren", + "cut": "Ausschneiden", + "drop file": "Datei hier ablegen", + "edit": "Bearbeiten", + "help": "Hilfe", + "hide others": "Andere ausblenden", + "hide": "Verstecken", + "learn more": "Erfahre mehr", + "open logs": "Öffne Logs", + "paste": "Einfügen", + "quit": "Beenden", + "unhide": "Alles anzeigen", + "update available": "Update verfügbar", + "update error": "Fehler beim Suchen nach Updates", + "update latest": "Deine Version ist aktuell" +} diff --git a/app/lib/i18n/de.json b/app/lib/i18n/de.json new file mode 100644 index 0000000..bcdd74d --- /dev/null +++ b/app/lib/i18n/de.json @@ -0,0 +1,24 @@ +{ + "about": "Über", + "check": "Check", + "check for updates": "Auf Updates überprüfen...", + "checksum match": "Übereinstimmung", + "checksum mismatch": "Die Checksums stimmen nicht überein", + "checksum fail": "Fehler - Hast du versucht einen Ordner hinzuzufügen?", + "choose file": "Datei wählen...", + "copy": "Kopieren", + "cut": "Ausschneiden", + "drop file": "Datei hier ablegen", + "edit": "Bearbeiten", + "help": "Hilfe", + "hide others": "Andere ausblenden", + "hide": "Verstecken", + "learn more": "Erfahre mehr", + "open logs": "Öffne Logs", + "paste": "Einfügen", + "quit": "Beenden", + "unhide": "Alles anzeigen", + "update available": "Update verfügbar", + "update error": "Fehler beim Suchen nach Updates", + "update latest": "Deine Version ist aktuell" +} diff --git a/app/lib/i18n/en-US.json b/app/lib/i18n/en-US.json new file mode 100644 index 0000000..5512046 --- /dev/null +++ b/app/lib/i18n/en-US.json @@ -0,0 +1,24 @@ +{ + "about": "About", + "check": "Check", + "check for updates": "Check for updates...", + "checksum match": "Checksum match", + "checksum mismatch": "Checksum mismatch", + "checksum fail": "Error - Did you try to add a directory ?", + "choose file": "Choose file", + "copy": "Copy", + "cut": "Cut", + "drop file": "Drop your file here", + "edit": "Edit", + "help": "Help", + "hide others": "Hide others", + "hide": "Hide", + "learn more": "Learn more", + "open logs": "Open Logs", + "paste": "Paste", + "quit": "Quit", + "unhide": "Unhide", + "update available": "Update available", + "update error": "Error while checking updates", + "update latest": "You have the latest version" +} diff --git a/app/main/src/i18n/en.json b/app/lib/i18n/en.json similarity index 57% rename from app/main/src/i18n/en.json rename to app/lib/i18n/en.json index f7320c5..74ed274 100644 --- a/app/main/src/i18n/en.json +++ b/app/lib/i18n/en.json @@ -1,6 +1,8 @@ { "about": "About", + "check": "Check", "check for updates": "Check for updates...", + "choose file": "Choose file", "copy": "Copy", "cut": "Cut", "edit": "Edit", @@ -11,5 +13,8 @@ "open logs": "Open Logs", "paste": "Paste", "quit": "Quit", - "unhide": "Unhide" + "unhide": "Unhide", + "update available": "Update available", + "update error": "Error while checking updates", + "update latest": "You have the latest version" } diff --git a/app/lib/i18n/i18n.ts b/app/lib/i18n/i18n.ts new file mode 100644 index 0000000..6b56820 --- /dev/null +++ b/app/lib/i18n/i18n.ts @@ -0,0 +1,42 @@ +import * as electron from 'electron'; +import log from 'electron-log'; +import * as fs from 'fs'; +import * as isRenderer from 'is-electron-renderer'; +import * as path from 'path'; +interface ILanguages { + [key: string]: string; +} + +class I18n { + + private loadedLanguage: ILanguages; + private app = electron.app ? electron.app : electron.remote.app; + + constructor() { + if (isRenderer) { + // we are invoking the i18n from the renderer and need another path + if (fs.existsSync(path.join(__dirname, '../build/' + this.app.getLocale() + '.json'))) { + this.loadedLanguage = JSON.parse(fs.readFileSync(path.join(__dirname, '../build/' + this.app.getLocale() + '.json'), 'utf8')); + } else { + this.loadedLanguage = JSON.parse(fs.readFileSync(path.join(__dirname, '../build/' + 'en.json'), 'utf8')); + } + } else { + if (fs.existsSync(path.join(__dirname, '/' + this.app.getLocale() + '.json'))) { + this.loadedLanguage = JSON.parse(fs.readFileSync(path.join(__dirname, '/' + this.app.getLocale() + '.json'), 'utf8')); + } else { + this.loadedLanguage = JSON.parse(fs.readFileSync(path.join(__dirname, 'en.json'), 'utf8')); + } + } + + } + + public translate(phrase: string): string { + let translation = this.loadedLanguage[phrase]; + if (translation === undefined) { + translation = phrase; + } + return translation; + } +} + +export default I18n; diff --git a/app/main/src/AppUpdater.ts b/app/main/src/AppUpdater.ts index fad84f7..4a1246e 100644 --- a/app/main/src/AppUpdater.ts +++ b/app/main/src/AppUpdater.ts @@ -1,14 +1,17 @@ import { dialog } from 'electron'; import log from 'electron-log'; import { autoUpdater } from 'electron-updater'; +import I18n from '../../lib/i18n/i18n'; import IPCHandler from './IPCHandler'; export default class AppUpdater { private ipcHandler: IPCHandler; + private i18n: I18n; constructor(ipcHandler: IPCHandler) { this.ipcHandler = ipcHandler; + this.i18n = new I18n(); autoUpdater.autoDownload = false; @@ -24,7 +27,7 @@ export default class AppUpdater { autoUpdater.on('error', (error) => { this.ipcHandler.sendToRenderer('update', { error: true, - msg: 'Error while checking updates ' + error, + msg: this.i18n.translate('update error') + ' ' + error, updateAvailable: false, }); }); @@ -32,7 +35,7 @@ export default class AppUpdater { autoUpdater.on('update-available', () => { this.ipcHandler.sendToRenderer('update', { error: false, - msg: 'Update available', + msg: this.i18n.translate('update available'), updateAvailable: true, }); }); @@ -53,7 +56,7 @@ export default class AppUpdater { autoUpdater.on('update-not-available', () => { this.ipcHandler.sendToRenderer('update', { error: false, - msg: 'You have the latest version', + msg: this.i18n.translate('update latest'), updateAvailable: false, }); }); diff --git a/app/main/src/MenuBuilder.ts b/app/main/src/MenuBuilder.ts index d948729..995acba 100644 --- a/app/main/src/MenuBuilder.ts +++ b/app/main/src/MenuBuilder.ts @@ -3,16 +3,18 @@ import { app, Menu, shell } from 'electron'; import * as fs from 'fs'; import * as path from 'path'; import * as username from 'username'; +import I18n from '../../lib/i18n/i18n'; import AppUpdater from './AppUpdater'; -import I18n from './i18n/i18n'; import IPCHandler from './IPCHandler'; export default class MenuBuilder { + private i18n: I18n; private updater: AppUpdater; constructor(updater: AppUpdater) { this.updater = updater; + this.i18n = new I18n(); } /** @@ -25,43 +27,43 @@ export default class MenuBuilder { { label: app.getName(), submenu: [ - { role: 'about', label: I18n.translate('about') }, + { role: 'about', label: this.i18n.translate('about') }, { click: () => { this.updater.checkForUpdate(); }, - label: I18n.translate('check for updates'), + label: this.i18n.translate('check for updates'), }, - { role: 'hide', label: I18n.translate('hide') }, - { role: 'hideothers', label: I18n.translate('hide others') }, - { role: 'unhide', label: I18n.translate('unhide') }, + { role: 'hide', label: this.i18n.translate('hide') }, + { role: 'hideothers', label: this.i18n.translate('hide others') }, + { role: 'unhide', label: this.i18n.translate('unhide') }, { type: 'separator' }, - { role: 'quit', label: I18n.translate('quit') }, + { role: 'quit', label: this.i18n.translate('quit') }, ], }, { - label: I18n.translate('edit'), + label: this.i18n.translate('edit'), submenu: [ { type: 'separator' }, - { role: 'cut', label: I18n.translate('cut') }, - { role: 'copy', label: I18n.translate('copy') }, - { role: 'paste', label: I18n.translate('paste') }, + { role: 'cut', label: this.i18n.translate('cut') }, + { role: 'copy', label: this.i18n.translate('copy') }, + { role: 'paste', label: this.i18n.translate('paste') }, ], }, { - label: I18n.translate('help'), role: 'help', + label: this.i18n.translate('help'), role: 'help', submenu: [ { click: () => { shell.openExternal('https://github.com/alexanderwe/checksum-validator'); }, - label: I18n.translate('learn more'), + label: this.i18n.translate('learn more'), }, { click: () => { shell.openItem(path.join('/Users/', username.sync(), '/Library/logs/checksum-validator/log.log')); }, - label: I18n.translate('open logs'), + label: this.i18n.translate('open logs'), }, ], }, diff --git a/app/main/src/i18n/i18n.ts b/app/main/src/i18n/i18n.ts deleted file mode 100644 index 8135d2d..0000000 --- a/app/main/src/i18n/i18n.ts +++ /dev/null @@ -1,34 +0,0 @@ -import * as electron from 'electron'; -import * as fs from 'fs'; -import * as path from 'path'; - -interface ILanguages { - [key: string]: string; -} - -class I18n { - - private loadedLanguage: ILanguages; - private app = electron.app ? electron.app : electron.remote.app; - - - - - constructor() { - if (fs.existsSync(path.join(__dirname, this.app.getLocale() + '.json'))) { - this.loadedLanguage = JSON.parse(fs.readFileSync(path.join(__dirname, this.app.getLocale() + '.json'), 'utf8')); - } else { - this.loadedLanguage = JSON.parse(fs.readFileSync(path.join(__dirname, 'en.json'), 'utf8')); - } - } - - public translate(phrase: string): string { - let translation = this.loadedLanguage[phrase]; - if (translation === undefined) { - translation = phrase; - } - return translation; - } -} - -export default new I18n(); diff --git a/app/main/src/main.ts b/app/main/src/main.ts index 5f3a8ca..8a39e53 100644 --- a/app/main/src/main.ts +++ b/app/main/src/main.ts @@ -34,7 +34,7 @@ function createWindow() { }); // and load the index.html of the app. - mainWindow.loadURL(`file://${__dirname}/../../renderer/index.html`); + mainWindow.loadURL(`file://${__dirname}/../renderer/index.html`); // Open the DevTools. if (process.env.ELECTRON_DEV) { @@ -49,6 +49,7 @@ function createWindow() { ipcHandler = new IPCHandler(mainWindow); appUpdater = new AppUpdater(ipcHandler); ipcHandler.updater = appUpdater; + console.log('main' + app.getLocale()); // Init the touchbar with ipcHandler support to send events to the renderer process mainWindow.setTouchBar(new TouchBarBuilder(ipcHandler).build()); diff --git a/app/package.json b/app/package.json index 52646a4..3996c60 100644 --- a/app/package.json +++ b/app/package.json @@ -1,14 +1,15 @@ { "name": "checksum-validator", - "version": "0.1.7", + "version": "0.2.0", "description": "Small Electron application to validate checksums.", - "main": "main/build/main.js", + "main": "build/main.js", "author": "Alexander Weiss", "dependencies": { "bulma": "^0.6.0", "classnames": "^2.2.5", "electron-log": "^2.2.10", "electron-updater": "^2.15.0", + "is-electron-renderer": "^2.0.1", "react": "^16.0.0", "react-dom": "^16.0.0", "react-transition-group": "^2.2.1", diff --git a/app/renderer/index.html b/app/renderer/index.html index cd67300..a2bd561 100644 --- a/app/renderer/index.html +++ b/app/renderer/index.html @@ -4,12 +4,12 @@