Skip to content

Commit

Permalink
feat: Localization, English + French (#40)
Browse files Browse the repository at this point in the history
Matching Ace Core PR: daisy/ace#223
  • Loading branch information
danielweck authored May 5, 2019
1 parent ee62a31 commit 93d21af
Show file tree
Hide file tree
Showing 33 changed files with 957 additions and 267 deletions.
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@
"postinstall": "electron-builder install-app-deps",
"release": "build -mw -p always",
"start": "node build/start.js",
"test": "echo TODO test the app"
"test": "echo TODO test the app",
"__replace-ace-packages": "npm run __rap1 && npm run __rap2 && npm run __rap3 && npm run __rap4 && npm run __rap5 && npm run __rap6 && npm run __rap7 && npm run __rap8 && npm run __rap9 && npm run __rap10 && npm run __rap11",
"__rap1": "rimraf \"node_modules/@daisy/puppeteer-utils/lib/**/*\" && cpy --cwd=\"../ace/packages/puppeteer-utils/lib/\" --parents --no-dir \"./**/*\" \"../../../../ace-gui/node_modules/@daisy/puppeteer-utils/lib/\" && cpy \"../ace/packages/puppeteer-utils/package.json\" \"./node_modules/@daisy/puppeteer-utils/\"",
"__rap2": "rimraf \"node_modules/@daisy/epub-utils/lib/**/*\" && cpy --cwd=\"../ace/packages/epub-utils/lib/\" --parents --no-dir \"./**/*\" \"../../../../ace-gui/node_modules/@daisy/epub-utils/lib/\" && cpy \"../ace/packages/epub-utils/package.json\" \"./node_modules/@daisy/epub-utils/\"",
"__rap3": "rimraf \"node_modules/@daisy/ace-report-axe/lib/**/*\" && cpy --cwd=\"../ace/packages/ace-report-axe/lib/\" --parents --no-dir \"./**/*\" \"../../../../ace-gui/node_modules/@daisy/ace-report-axe/lib/\" && cpy \"../ace/packages/ace-report-axe/package.json\" \"./node_modules/@daisy/ace-report-axe/\"",
"__rap4": "rimraf \"node_modules/@daisy/ace-report/lib/**/*\" && cpy --cwd=\"../ace/packages/ace-report/lib/\" --parents --no-dir \"./**/*\" \"../../../../ace-gui/node_modules/@daisy/ace-report/lib/\" && cpy \"../ace/packages/ace-report/package.json\" \"./node_modules/@daisy/ace-report/\"",
"__rap5": "rimraf \"node_modules/@daisy/ace-core/lib/**/*\" && cpy --cwd=\"../ace/packages/ace-core/lib/\" --parents --no-dir \"./**/*\" \"../../../../ace-gui/node_modules/@daisy/ace-core/lib/\" && cpy \"../ace/packages/ace-core/package.json\" \"./node_modules/@daisy/ace-core/\"",
"__rap6": "rimraf \"node_modules/@daisy/ace-config/lib/**/*\" && cpy --cwd=\"../ace/packages/ace-config/lib/\" --parents --no-dir \"./**/*\" \"../../../../ace-gui/node_modules/@daisy/ace-config/lib/\" && cpy \"../ace/packages/ace-config/package.json\" \"./node_modules/@daisy/ace-config/\"",
"__rap7": "rimraf \"node_modules/@daisy/ace-logger/lib/**/*\" && cpy --cwd=\"../ace/packages/ace-logger/lib/\" --parents --no-dir \"./**/*\" \"../../../../ace-gui/node_modules/@daisy/ace-logger/lib/\" && cpy \"../ace/packages/ace-logger/package.json\" \"./node_modules/@daisy/ace-logger/\"",
"__rap8": "cpy \"../ace/packages/ace-meta/package.json\" \"./node_modules/@daisy/ace-meta/\"",
"__rap9": "rimraf \"node_modules/@daisy/ace-localize/lib/**/*\" && cpy --cwd=\"../ace/packages/ace-localize/lib/\" --parents --no-dir \"./**/*\" \"../../../../ace-gui/node_modules/@daisy/ace-localize/lib/\" && cpy \"../ace/packages/ace-localize/package.json\" \"./node_modules/@daisy/ace-localize/\"",
"__rap10": "cpy --cwd=\"../ace/node_modules/\" --parents --no-dir \"./axe-core/**/*\" \"../../ace-gui/node_modules/\"",
"__rap11": "cpy --cwd=\"../ace/node_modules/\" --parents --no-dir \"./i18next/**/*\" \"../../ace-gui/node_modules/\""
},
"dependencies": {
"@daisy/ace-config": "^1.0.0",
Expand All @@ -58,6 +70,7 @@
"about-window": "^1.12.1",
"electron-debug": "^2.0.0",
"electron-redux": "^1.3.1",
"electron-store": "^2.0.0",
"express": "^4.16.4",
"fs-jetpack": "^2.1.0",
"jszip": "^3.1.5",
Expand Down
123 changes: 70 additions & 53 deletions src/main/kb.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const fs = require('fs');
const { BrowserWindow, webContents } = require('electron');
import { app, shell, session, ipcMain, Menu } from 'electron';

import { localizer } from './../shared/l10n/localize';
const { localize } = localizer;

import * as AboutBoxHelper from './../shared/helpers/about';

import * as express from "express";
Expand Down Expand Up @@ -158,7 +161,7 @@ export function startKnowledgeBaseServer(kbRootPath) {

const toMatch1 = "document.location.host == 'localhost'";
const toMatch2 = "KB.prototype.generateFooter = function () {";
const link = "GO ONLINE";
const link = localize("kbgoonline");
const online = `
var zhref = document.location.href.replace('${rootUrl}/', 'http://kb.daisy.org/');
var zdiv = document.createElement('div');
Expand Down Expand Up @@ -246,70 +249,72 @@ function buildMenuTemplate(win) {

const defaultTemplate = {
subMenuEdit: {
label: 'Edit',
label: localize('menu.edit'),
submenu: [
{
label: "Undo",
label: localize('menu.undo'),
accelerator: "CmdOrCtrl+Z",
selector: "undo:"
},
{
label: "Redo",
label: localize('menu.redo'),
accelerator: "Shift+CmdOrCtrl+Z",
selector: "redo:"
},
{ type: "separator" },
{
label: "Cut",
label: localize('menu.cut'),
accelerator: "CmdOrCtrl+X",
selector: "cut:"
},
{
label: "Copy",
label: localize('menu.copy'),
accelerator: "CmdOrCtrl+C",
selector: "copy:"
},
{
label: "Paste",
label: localize('menu.paste'),
accelerator: "CmdOrCtrl+V",
selector: "paste:"
},
{
label: "Select All",
label: localize('menu.selectall'),
accelerator: "CmdOrCtrl+A",
selector: "selectAll:"
},
],
},
subMenuDev: {
label: 'Dev',
label: localize('menu.dev'),
submenu: [
{
label: 'Reload',
label: localize('menu.reload'),
id: 'reload',
accelerator: 'CmdOrCtrl+R',
click: () => {
const bw = BrowserWindow.getFocusedWindow();
if (bw) {
bw.webContents.reload();
} else {
win.webContents.reload();
// const arr = BrowserWindow.getAllWindows();
// arr.forEach((bww) => {
// bww.webContents.openDevTools({ mode: "detach" });
// });
// for (const wc of webContents.getAllWebContents()) {
// // if (wc.hostWebContents &&
// // wc.hostWebContents.id === win.webContents.id) {
// // }
// wc.openDevTools({ mode: "detach" });
// }
}
const bw = BrowserWindow.getFocusedWindow();
if (bw) {
bw.webContents.reload();
} else {
win.webContents.reload();

// const arr = BrowserWindow.getAllWindows();
// arr.forEach((bww) => {
// bww.webContents.openDevTools({ mode: "detach" });
// });

// for (const wc of webContents.getAllWebContents()) {
// // if (wc.hostWebContents &&
// // wc.hostWebContents.id === win.webContents.id) {
// // }
// wc.openDevTools({ mode: "detach" });
// }
}
}
},
{
label: 'Toggle Developer Tools',
label: localize('menu.toggleDevTools'),
id: 'toggleDevTools',
accelerator: 'Alt+CmdOrCtrl+I',
click: () => {
// win.toggleDevTools();
Expand Down Expand Up @@ -339,77 +344,88 @@ function buildMenuTemplate(win) {
]
},
subMenuHelp: {
label: 'Help',
label: localize('menu.help'),
role: 'help',
submenu: [
{
label: 'Learn more',
label: localize('menu.learnMore'),
id: 'learnMore',
click: () => shell.openExternal('http://daisy.github.io/ace')
},
{
label: 'Report an Issue',
label: localize('menu.reportIssue'),
id: 'reportIssue',
click: () => shell.openExternal('http://github.com/DAISY/ace-gui/issues')
},
}
]
},
subMenuAbout: {
label: 'Ace',
label: localize('menu.ace'),
submenu: [
{
label: 'About Ace',
id: 'about',
label: localize('menu.about'),
id: 'about2',
click: () => AboutBoxHelper.showAbout()
},
{
type: 'separator'
},
{
// label: 'Services',
// label: localize('menu.services'),
id: 'services',
role: 'services',
submenu: []
},
{
type: 'separator'
},
{
// label: 'Hide Ace',
// accelerator: 'CmdOrCtrl+H',
// label: localize('menu.hideAce'),
id: 'hideAce',
// accelerator: 'Command+H',
role: 'hide'
},
{
// label: 'Hide Others',
// accelerator: 'CmdOrCtrl+Alt+H',
// label: localize('menu.hideOthers'),
id: 'hideOthers',
// accelerator: 'Command+Alt+H',
role: 'hideothers'
},
{
// label: 'Show All',
// label: localize('menu.showAll'),
id: 'showAll',
role: 'unhide'
},
{
type: 'separator'
},
{
label: localize('menu.quit'),
id: 'quit2',
role: 'quit'
}
]
},
subMenuWindow: {
label: 'Window',
label: localize('menu.window'),
role: 'window',
submenu: [
// {
// label: 'Toggle Full Screen',
// type: 'checkbox',
// accelerator: process.platform === 'darwin'
// ? 'Ctrl+Command+F'
// : 'F11',
// click: () => win.setFullScreen(!win.isFullScreen())
// label: 'Toggle Full Screen',
// type: 'checkbox',
// accelerator: process.platform === 'darwin'
// ? 'Ctrl+Command+F'
// : 'F11',
// click: () => win.setFullScreen(!win.isFullScreen())
// },
{
// label: localize('menu.togglefullscreen'),
role: "togglefullscreen",
},
{
role: "minimize",
// label: localize('menu.minimize'),
id: 'minimize',
role: 'minimize'
},
{
role: "close",
Expand All @@ -420,7 +436,8 @@ function buildMenuTemplate(win) {
// },
{ type: 'separator' },
{
// label: 'Bring All to Front',
// label: localize('menu.bringToFront'),
id: 'bringToFront',
role: 'front'
}
]
Expand All @@ -438,8 +455,8 @@ function buildMenuTemplate(win) {
type: 'separator'
},
{
label: 'About Ace',
id: 'about',
label: localize('menu.about'),
id: 'about1',
click: () => AboutBoxHelper.showAbout()
}
);
Expand Down
26 changes: 19 additions & 7 deletions src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ const path = require('path');
const { app, BrowserWindow, webContents} = require('electron');

import MenuBuilder from './menu';
import configureStore from './../shared/store/configureStore';

import {initPersistentStore} from './store-persist';

require('electron-debug')();

const {store, storeSubscribe, storeUnsubscribe} = initPersistentStore();

import {startKnowledgeBaseServer, stopKnowledgeBaseServer, closeKnowledgeBaseWindows} from './kb';

function openAllDevTools() {
Expand All @@ -29,9 +32,9 @@ function openTopLevelDevTools() {
}
}

const store = configureStore(undefined, 'main');
let win;
function createWindow() {

win = new BrowserWindow({ show: false });
win.maximize();
let sz = win.getSize();
Expand All @@ -47,12 +50,19 @@ function createWindow() {
const menuBuilder = new MenuBuilder(win, store);
menuBuilder.buildMenu(win);

const cb = () => {
menuBuilder.storeHasChanged();
};
storeSubscribe(cb);

win.loadURL(`file://${__dirname}/index.html`);

win.on('closed', function () {
win = null;
app.quit();

storeUnsubscribe(cb);

win = null;

// closeKnowledgeBaseWindows();

// // about box
Expand All @@ -61,11 +71,14 @@ function createWindow() {
// bw.close();
// });

// will trigger window-all-closed event => app quit
// the above triggers window-all-closed event => app quit

app.quit();
});
}

app.setAccessibilitySupportEnabled(true);
// Is enabled automatically when screen reader is detected
// app.setAccessibilitySupportEnabled(true);

app.on('ready', () => {
let isDev = process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true';
Expand Down Expand Up @@ -96,5 +109,4 @@ app.on('activate', function () {
});

app.on('before-quit', function() {
// TODO persist anything that needs persisting
});
Loading

0 comments on commit 93d21af

Please sign in to comment.