mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-30 09:44:26 +02:00
moar trans
This commit is contained in:
parent
91555e9bf9
commit
19fba12e67
1 changed files with 34 additions and 10 deletions
|
@ -44,6 +44,8 @@ var translate = function(context, path, key, blob, schema) {
|
||||||
// CONFIG stuff
|
// CONFIG stuff
|
||||||
var findLevelsCommand = 'find ../../levels -name "*.js"';
|
var findLevelsCommand = 'find ../../levels -name "*.js"';
|
||||||
|
|
||||||
|
// START functions
|
||||||
|
|
||||||
var processLevelIndex = function() {
|
var processLevelIndex = function() {
|
||||||
var path = '../../levels';
|
var path = '../../levels';
|
||||||
var sequenceInfo = require(path).sequenceInfo;
|
var sequenceInfo = require(path).sequenceInfo;
|
||||||
|
@ -71,14 +73,16 @@ var processLevelIndex = function() {
|
||||||
genNameContext(sequence),
|
genNameContext(sequence),
|
||||||
path,
|
path,
|
||||||
'displayName',
|
'displayName',
|
||||||
sequence.displayName
|
sequence.displayName,
|
||||||
|
titleSchema
|
||||||
);
|
);
|
||||||
|
|
||||||
translate(
|
translate(
|
||||||
genAboutContext(sequence),
|
genAboutContext(sequence),
|
||||||
path,
|
path,
|
||||||
'about',
|
'about',
|
||||||
sequence.about
|
sequence.about,
|
||||||
|
aboutSchema
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -151,10 +155,20 @@ var printSeparator = function() {
|
||||||
printLn();
|
printLn();
|
||||||
};
|
};
|
||||||
|
|
||||||
var collectInput = function(cb) {
|
var collectInput = function(schema, cb) {
|
||||||
prompt.get(schema, function(err, result) {
|
var defer = Q.defer();
|
||||||
cb(result);
|
Q.nfcall(prompt.get, schema)
|
||||||
});
|
.then(defer.resolve)
|
||||||
|
.fail(defer.reject)
|
||||||
|
.done();
|
||||||
|
return defer.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
var getInput = function(obj) {
|
||||||
|
if (!obj || !_.keys(obj).length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return obj[_.keys(obj)[0]];
|
||||||
};
|
};
|
||||||
|
|
||||||
var popTranslateQueue = function(queueObj) {
|
var popTranslateQueue = function(queueObj) {
|
||||||
|
@ -162,11 +176,17 @@ var popTranslateQueue = function(queueObj) {
|
||||||
printSeparator();
|
printSeparator();
|
||||||
printContext(queueObj);
|
printContext(queueObj);
|
||||||
|
|
||||||
collectInput(function(input) {
|
collectInput(queueObj.schema)
|
||||||
|
.then(function(inputObj) {
|
||||||
|
var input = getInput(inputObj);
|
||||||
|
|
||||||
console.log(input);
|
console.log(input);
|
||||||
outputTranslation(queueObj, input);
|
outputTranslation(queueObj, input);
|
||||||
defer.resolve();
|
defer.resolve();
|
||||||
});
|
})
|
||||||
|
.fail(defer.reject)
|
||||||
|
.done();
|
||||||
|
|
||||||
return defer.promise;
|
return defer.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -198,7 +218,7 @@ var appendLineAfterNeedleToFile = function(path, needle, line) {
|
||||||
var fileContents = fs.readFileSync(endPath).toString();
|
var fileContents = fs.readFileSync(endPath).toString();
|
||||||
var fileLines = fileContents.split('\n');
|
var fileLines = fileContents.split('\n');
|
||||||
|
|
||||||
var toEscape = '()[]?+*'.split('');
|
var toEscape = '()[]?+*\''.split('');
|
||||||
_.each(toEscape, function(chr) {
|
_.each(toEscape, function(chr) {
|
||||||
needle = needle.replace(chr, '\\' + chr);
|
needle = needle.replace(chr, '\\' + chr);
|
||||||
});
|
});
|
||||||
|
@ -213,6 +233,7 @@ var appendLineAfterNeedleToFile = function(path, needle, line) {
|
||||||
|
|
||||||
if (numberMatches !== 1) {
|
if (numberMatches !== 1) {
|
||||||
console.log('WARNING couldnt find needle\n', needle, 'in path\n', endPath);
|
console.log('WARNING couldnt find needle\n', needle, 'in path\n', endPath);
|
||||||
|
console.log(numberMatches);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,6 +252,7 @@ var outputTranslation = function(queueObj, input) {
|
||||||
|
|
||||||
shouldBegin.promise
|
shouldBegin.promise
|
||||||
.then(function() {
|
.then(function() {
|
||||||
|
console.log('translating ' + translateQueue.length + ' items');
|
||||||
// the tricky thing here is that we need to make a chain of promises
|
// the tricky thing here is that we need to make a chain of promises
|
||||||
var popChain = Q.defer();
|
var popChain = Q.defer();
|
||||||
var promise = popChain.promise;
|
var promise = popChain.promise;
|
||||||
|
@ -239,8 +261,10 @@ shouldBegin.promise
|
||||||
return popTranslateQueue(queueItem);
|
return popTranslateQueue(queueItem);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
promise.fail(function(err) {
|
||||||
|
console.log('ERROR:\n' + err);
|
||||||
|
});
|
||||||
|
|
||||||
popChain.resolve();
|
popChain.resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue