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 @@ Checksum Validator - +
- + \ No newline at end of file diff --git a/app/renderer/src/components/Checksum.component.tsx b/app/renderer/src/components/Checksum.component.tsx index 8a3139f..e228260 100644 --- a/app/renderer/src/components/Checksum.component.tsx +++ b/app/renderer/src/components/Checksum.component.tsx @@ -4,6 +4,7 @@ import Transition from 'react-transition-group/Transition'; import Button from './bulma/element/Button.component'; import Icon from './bulma/element/Icon.component'; + import Notification from './bulma/element/Notification.component'; import Form from './bulma/form/Form.component'; import Container from './bulma/layout/Container.component'; @@ -13,6 +14,10 @@ import FadeAndSlideDownTransition from './transition/FadeAndSlideDownTransition. import Tag from './bulma/element/Tag.component'; +import I18n from '../../../lib/i18n/i18n'; + +const i18n: I18n = new I18n(); + interface IUpdateMsg { error: boolean; msg: string; @@ -182,15 +187,15 @@ class ChecksumValidator extends React.Component { this.closeNotification()}> {!this.state.checksumResult ?
- Failed - did you try to compute the checksum of an directory ? -
: this.state.match ? ( -
- Checksum match + {i18n.translate('checksum fail')} +
: this.state.match ? ( +
+ {i18n.translate('checksum match')}
- ) : ( + ) : (
- Checksum mismatch -
+ {i18n.translate('checksum mismatch')} + )}
@@ -199,7 +204,7 @@ class ChecksumValidator extends React.Component {

- Drop your file here + {i18n.translate('drop file')}

@@ -208,7 +213,7 @@ class ChecksumValidator extends React.Component {
- + @@ -226,7 +231,7 @@ class ChecksumValidator extends React.Component {
{this.state.updateMsg ? diff --git a/app/yarn.lock b/app/yarn.lock index e974f61..5e06afd 100644 --- a/app/yarn.lock +++ b/app/yarn.lock @@ -148,6 +148,10 @@ iconv-lite@~0.4.13: version "0.4.19" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b" +is-electron-renderer@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/is-electron-renderer/-/is-electron-renderer-2.0.1.tgz#a469d056f975697c58c98c6023eb0aa79af895a2" + is-stream@^1.0.1, is-stream@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" diff --git a/package.json b/package.json index 18e073b..524d358 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "checksum-validator", - "version": "0.1.7", + "version": "0.2.0", "description": "Small Electron application to validate checksums.", "main": "main.js", "scripts": { @@ -10,7 +10,7 @@ "dist": "build -m --x64 --ia32", "postinstall": "install-app-deps", "release": "build", - "start": "ELECTRON_DEV=1 electron app/main/build/main.js", + "start": "ELECTRON_DEV=1 electron app/build/main.js", "test": "mocha", "tsc:watch": "tsc --watch --p tsconfig.json --declaration --target es5" }, diff --git a/test/test.ts b/test/test.ts index 984361f..a6778d7 100644 --- a/test/test.ts +++ b/test/test.ts @@ -11,7 +11,7 @@ chai.should(); beforeEach(() => { this.app = new Application({ - args: ['app/main/build/main.js'], + args: ['app/build/main.js'], path: 'node_modules/.bin/electron', }); diff --git a/webpack.config.js b/webpack.config.js index a82241c..edb096c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -12,11 +12,15 @@ module.exports = function(env) { let rendererConfig = Object.assign({}, config, { watch: env.mode == 'watch' ? true : false, target: 'electron-renderer', + node: { + __dirname: false, + __filename: false + }, entry: './app/renderer/src/entry.tsx', output: { - path: __dirname + '/app/renderer/build', + path: __dirname + '/app/build/', publicPath: 'build/', - filename: 'bundle.js' + filename: 'renderer.js' }, resolve: { // Add '.ts' and '.tsx' as resolvable extensions. @@ -85,7 +89,7 @@ module.exports = function(env) { externals: [nodeExternals()], watch: env.mode == 'watch' ? true : false, output: { - filename: './app/main/build/main.js' + filename: './app/build/main.js' }, resolve: { extensions: ['.ts', '.js', '.json'] @@ -93,7 +97,7 @@ module.exports = function(env) { module: { loaders: [{ test: /.ts$/, loader: 'awesome-typescript-loader' }] }, - plugins: [new CopyWebpackPlugin([{ from: 'app/main/src/i18n/', to: 'app/main/build/' }], { ignore: ['*.ts'] }), new DashboardPlugin()] + plugins: [new CopyWebpackPlugin([{ from: 'app/lib/i18n/', to: 'app/build/' }], { ignore: ['*.ts'] }), new DashboardPlugin()] }); return [rendererConfig, mainConfig];