Skip to content

Commit

Permalink
Merge pull request #1273 from unfoldingWord-dev/joel/enhancement/57/m…
Browse files Browse the repository at this point in the history
…ultilingual-ta

Add multilingual support to tA
  • Loading branch information
da1nerd authored Oct 23, 2019
2 parents 4fd40bd + bcf573f commit 7de0f8a
Show file tree
Hide file tree
Showing 50 changed files with 15,849 additions and 6,935 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/env", "@babel/react"]
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ The following commands are available from within the project directory:

> Note: You can open the Chrome Developer Tools while the app is running by pressing `Ctrl+Shift+I` on Windows/Linux or `Cmd-Shift-I` on macOS.
### Building tA
tA has been built using react and es6. If you need to work on this part of the code, work in `src/js/academy-es6` and then run `npm run compile-ta`.

### Included Resources
The application is bundled with resources from the following languages

Expand Down
47 changes: 31 additions & 16 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,29 @@ const gulp = require('gulp'),
mkdirp = require('mkdirp'),
fs = require('fs'),
util = require('./src/js/lib/utils'),
princePackager = require('./src/js/prince-packager');
princePackager = require('./src/js/prince-packager'),
requireES6 = require('./src/js/require-es6'),
{ pack: packagetA } = requireES6(path.join(__dirname, './src/js/academy/package-ta'));

const APP_NAME = 'translationStudio',
JS_FILES = './src/js/**/*.js',
UNIT_TEST_FILES = './unit_tests/**/*.js',
BUILD_DIR = 'out/',
RELEASE_DIR = 'release/';

gulp.task('test', function () {
function test() {
return gulp.src(UNIT_TEST_FILES, { read: false })
.pipe(mocha({reporter: 'spec', grep: (argv.grep || argv.g)}));
});
}

gulp.task('clean', function () {
function clean(done) {
rimraf.sync('src/logs');
rimraf.sync('logs');
rimraf.sync('ssh');
});
done();
}

gulp.task('bump', function () {
function bump() {
var build = require('./package').build;

var bumped = ++build;
Expand All @@ -44,23 +47,23 @@ gulp.task('bump', function () {
return gulp.src(['package.json'])
.pipe(replace(/("build"\s*:\s*)"\d+"(.*)/, replaceString))
.pipe(gulp.dest('./'));
});
}

/**
* This will download and install prince binaries for all os'
*/
gulp.task('prince', function(done) {
function prince(done) {
var tempDir = 'src/prince';

util.chain(princePackager.install.bind(null, tempDir))(['win', 'linux', 'osx'])
.then(function() {
done();
})
.catch(done);
});
}

// pass parameters like: gulp build --win --osx --linux
gulp.task('build', ['clean'], function (done) {
function build(done) {

var platforms = [];

Expand All @@ -80,13 +83,13 @@ gulp.task('build', ['clean'], function (done) {
RELEASE_DIR,
'vendor',
'scripts',
'\\.'
'\\.(?!babelrc)'
]).map(function (name) {
return new RegExp('(^/' + name + '|' + '^/node_modules/' + name + ')');
});

packager({
'asar': true,
'asar': false,
'arch': argv.win ? 'all' : 'x64',
'platform': platforms,
'dir': '.',
Expand Down Expand Up @@ -129,9 +132,9 @@ gulp.task('build', ['clean'], function (done) {
// }
// });
// }
});
}

gulp.task('release', function(done) {
function release(done) {
const p = require('./package');
const archiver = require('archiver');
const exec = require('child_process').exec;
Expand Down Expand Up @@ -329,6 +332,18 @@ gulp.task('release', function(done) {
done();
}).catch(done);
});
});
}

gulp.task('default', ['test']);
function packTA() {
return packagetA(path.join(__dirname, './src/index/ta'));
}


module.exports.default = test;
module.exports.test = test;
module.exports.release = release;
module.exports.packTA = packTA;
module.exports.build = gulp.series(clean, build);
module.exports.prince = prince;
module.exports.bump = bump;
module.exports.clean = clean;
74 changes: 51 additions & 23 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const {dialog, app, Menu, BrowserWindow, ipcMain} = require(
'electron');
const path = require('path');
const mkdirp = require('mkdirp');

const debug = /--debug/.test(process.argv[2]);

Expand Down Expand Up @@ -45,15 +46,20 @@ const menuTemplate = [
{ role: 'editMenu' }
];

function getDataPath() {
var base = process.env.LOCALAPPDATA || (process.platform === 'darwin' ?
path.join(process.env.HOME, 'Library', 'Application Support') :
path.join(process.env.HOME, '.config'));

const dir = path.join(base, 'translationstudio');
mkdirp.sync(dir);
return dir;
}

function initialize() {
makeSingleInstance();

app.setPath('userData', (function(dataDir) {
var base = process.env.LOCALAPPDATA ||
(process.platform === 'darwin' ? path.join(process.env.HOME, 'Library', 'Application Support') : path.join(process.env.HOME, '.config'));

return path.join(base, dataDir);
})('translationstudio'));
app.setPath('userData', getDataPath());

app.on('ready', () => {
createSplashWindow();
Expand Down Expand Up @@ -120,16 +126,42 @@ function initialize() {
}
});

ipcMain.on('open-academy', function(event, id) {
scrollToId = id;
/**
* Handles an event to open translationAcademy
* @param event
* @param lang - the translation to view
* @param id - the article id
*/
ipcMain.on('open-academy', function(event, args) {
let lang, id;
if(args) {
lang = args.lang;
id = args.id;
}

if (academyWindow) {
academyWindow.show();
scrollAcademyWindow();
// send props to window
academyWindow.webContents.send('props', {
lang,
articleId: id,
dataPath: getDataPath()
});
} else {
createAcademySplash();
setTimeout(function() {
splashScreen.show();
createAcademyWindow();
academyWindow.once('ready-to-show', () => {
splashScreen.close();
academyWindow.show();
// send props to window
academyWindow.webContents.send('props', {
lang,
articleId: id,
dataPath: getDataPath()
});
});
}, 500);
}
});
Expand Down Expand Up @@ -160,14 +192,6 @@ function initialize() {
var input = dialog.showOpenDialog(mainWindow, arg.options);
event.returnValue = input || false;
});

ipcMain.on('ta-loading-done', function() {
if (splashScreen && academyWindow) {
academyWindow.show();
splashScreen.close();
scrollAcademyWindow();
}
});
}

function createWindow() {
Expand All @@ -194,6 +218,10 @@ function createWindow() {
path.join('file://', __dirname, '/src/views/index.html'));

mainWindow.on('closed', () => {
if (academyWindow) {
academyWindow.close();
academyWindow = null;
}
mainWindow = null;
});

Expand Down Expand Up @@ -308,7 +336,8 @@ function createAcademyWindow() {
frame: false
});

academyWindow.loadURL('file://' + path.join(__dirname, '/src/views/academy.html'));
academyWindow.loadURL(
'file://' + path.join(__dirname, '/src/views/academy.html'));

academyWindow.on('closed', function() {
academyWindow = null;
Expand All @@ -321,12 +350,11 @@ function createAcademyWindow() {
academyWindow.on('unmaximize', function() {
academyWindow.webContents.send('unmaximize');
});
}

function scrollAcademyWindow() {
if (scrollToId) {
academyWindow.webContents.send('academy-scroll', scrollToId);
}
academyWindow.on('blur', function() {
// manually pass blur to the page because window.blur doesn't work properly.
academyWindow.webContents.send('blur');
});
}

initialize();
Loading

0 comments on commit 7de0f8a

Please sign in to comment.