Skip to content

Commit

Permalink
Update auto translation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJaredWilcurt committed Jan 3, 2018
1 parent 27934ad commit 2d8eb7b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -67,8 +67,8 @@
"start": "nw .",
"installer": "npm install --loglevel=error",
"postinstall": "bower update",
"lint": "eslint --config=.eslintrc.js scout-files/_scripts build.js cultures.js translate.js",
"fix": "eslint --fix --config=.eslintrc.js scout-files/_scripts build.js cultures.js translate.js",
"lint": "eslint --config=.eslintrc.js scout-files/_scripts build.js cultures.js translate.js translate2.js",
"fix": "eslint --fix --config=.eslintrc.js scout-files/_scripts build.js cultures.js translate.js translate2.js",
"sasslint": "node sasslinter.js",
"cultures": "node cultures.js",
"translations": "node cultures.js",
Expand Down
24 changes: 19 additions & 5 deletions translate.js
@@ -1,11 +1,10 @@
/* eslint-disable no-console */

var fs = require('fs-extra');
var path = require('path');
var translate = require('google-translate-api');
// Translate one phrase into a bunch of languages

var input = 'Files';
// SETTINGS

var input = 'Phrase to be translated.';
var supportedLangs = [
'ar',
'bg',
Expand All @@ -16,6 +15,7 @@ var supportedLangs = [
'fa',
'fi',
'fr',
'id',
'iw',
'hu',
'it',
Expand All @@ -33,12 +33,26 @@ var supportedLangs = [
'zh-TW',
'zh-CN'
];

var translations = {
'en': input,
'rk': input
};










// CODE

var fs = require('fs-extra');
var path = require('path');
var translate = require('google-translate-api');

function saveFile () {
var file = path.join('.', 'translated.txt');
var sorted = JSON.stringify(translations, Object.keys(translations).sort(), 2);
Expand Down
74 changes: 74 additions & 0 deletions translate2.js
@@ -0,0 +1,74 @@
/* eslint-disable no-console */

// Translate a bunch of phrases into one language.


// SETTINGS

var inputs = {
'VIEW_LATEST_RELEASE': 'View latest release',
'WELCOME_MESSAGE': 'Welcome to Scout-App!',
'WINDOW_SETTING': 'Window'
};

var translateFrom = 'en';
var translateTo = 'id';






// CODE

var fs = require('fs-extra');
var path = require('path');
var translate = require('google-translate-api');

var total = 0;
var totalLength = Object.keys(inputs).length;
var inputsArray = Object.entries(inputs);
var translations = {};

function saveFile () {
var file = path.join('.', 'translated.txt');
var sorted = JSON.stringify(translations, Object.keys(translations).sort(), 2);
var data = sorted + '\n';

fs.writeFileSync(file, data);
}

inputsArray.forEach(function (input) {
var key = input[0];
var phrase = input[1];
var settings = {
from: translateFrom,
to: translateTo
};
if (phrase === '.') {
translations[key] = '.';
total = total + 1;
if (total == totalLength) {
saveFile();
}
} else {
translate(phrase, settings).then(function (response) {
var translation = response.text;

translations[key] = translation;

total = total + 1;
if (total == totalLength) {
saveFile();
}
}.bind(this)).catch(function (err) {
console.log('==================================');
console.error(err);

total = total + 1;
if (total == totalLength) {
saveFile();
}
}.bind(this));
}
});

0 comments on commit 2d8eb7b

Please sign in to comment.