Skip to content

Commit

Permalink
Merge pull request #12 from alexanderwe/feature/addInternalization
Browse files Browse the repository at this point in the history
Feature/add internalization
  • Loading branch information
alexanderwe authored Nov 10, 2017
2 parents 89bd219 + e08a03f commit 3406a37
Show file tree
Hide file tree
Showing 19 changed files with 228 additions and 76 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Webpack
app/renderer/build
app/main/build
app/build

# Logs
logs
Expand Down
24 changes: 24 additions & 0 deletions app/lib/i18n/de-AT.json
Original file line number Diff line number Diff line change
@@ -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"
}
24 changes: 24 additions & 0 deletions app/lib/i18n/de-CH.json
Original file line number Diff line number Diff line change
@@ -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"
}
24 changes: 24 additions & 0 deletions app/lib/i18n/de-DE.json
Original file line number Diff line number Diff line change
@@ -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"
}
24 changes: 24 additions & 0 deletions app/lib/i18n/de.json
Original file line number Diff line number Diff line change
@@ -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"
}
24 changes: 24 additions & 0 deletions app/lib/i18n/en-US.json
Original file line number Diff line number Diff line change
@@ -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"
}
7 changes: 6 additions & 1 deletion app/main/src/i18n/en.json → app/lib/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"about": "About",
"check": "Check",
"check for updates": "Check for updates...",
"choose file": "Choose file",
"copy": "Copy",
"cut": "Cut",
"edit": "Edit",
Expand All @@ -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"
}
42 changes: 42 additions & 0 deletions app/lib/i18n/i18n.ts
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 6 additions & 3 deletions app/main/src/AppUpdater.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -24,15 +27,15 @@ 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,
});
});

autoUpdater.on('update-available', () => {
this.ipcHandler.sendToRenderer('update', {
error: false,
msg: 'Update available',
msg: this.i18n.translate('update available'),
updateAvailable: true,
});
});
Expand All @@ -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,
});
});
Expand Down
30 changes: 16 additions & 14 deletions app/main/src/MenuBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand All @@ -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'),
},
],
},
Expand Down
34 changes: 0 additions & 34 deletions app/main/src/i18n/i18n.ts

This file was deleted.

3 changes: 2 additions & 1 deletion app/main/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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());
Expand Down
5 changes: 3 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Loading

0 comments on commit 3406a37

Please sign in to comment.