awesome getting translation script mostly there

This commit is contained in:
Peter Cottle 2013-03-03 17:00:50 -08:00
parent da51a115ae
commit 5290a9878f
2 changed files with 160 additions and 1 deletions

View file

@ -0,0 +1,159 @@
/*
* Warning!! This is this hackiest goddamn script evarrr. Don't
* judge :D
*/
var child_process = require('child_process');
var _ = require('underscore');
var Q = require('q');
var intl = require('../intl');
var shouldBegin = Q.defer();
var translateQueue = [];
var translate = function(context, path, key, blob) {
translateQueue.push({
context: context,
path: path,
key: key,
blob: blob
});
};
// CONFIG stuff
var findLevelsCommand = 'find ../../levels -name "*.js"';
var processLevelIndex = function() {
var path = '../../levels';
var sequenceInfo = require(path).sequenceInfo;
var genNameContext = function(sequence) {
var name = intl.getIntlKey(sequence, 'displayName');
return [
'This is a title of a level sequence "' + name + '" ',
'What is the best translation for that title?'
].join('\n');
};
var genAboutContext = function(sequence) {
var name = intl.getIntlKey(sequence, 'displayName');
var about = intl.getIntlKey(sequence, 'about');
return [
'For the level sequence "' + name + '",',
'the about section is:',
'~~"' + about + '"',
'',
'What is the best translation for the about section?'
].join('\n');
};
_.each(sequenceInfo, function(sequence) {
translate(
genNameContext(sequence),
path,
'displayName',
sequence.displayName
);
translate(
genAboutContext(sequence),
path,
'about',
sequence.about
);
});
};
var processLevel = function(levelPath) {
if (/index.js/.test(levelPath)) {
return;
}
var level = require(levelPath).level;
// TODO
};
child_process.exec(findLevelsCommand, function(err, output) {
_.each(output.split('\n'), function(levelPath) {
if (!levelPath || !levelPath.length) {
return;
}
processLevel(levelPath);
});
processLevelIndex();
shouldBegin.resolve();
});
var printContext = function(queueObj) {
if (typeof queueObj.context === 'string') {
console.log(queueObj.context);
} else {
var results = queueObj.context();
if (results) { console.log(results); }
}
};
var printSeparator = function() {
var printLn = function() {
console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
};
var printSpace = function(num) {
num = (num === undefined) ? 1 : num;
for (var i = 0; i < num; i++) {
console.log('\n');
}
};
var printRandomEmoji = function() {
var emojis = [
':D',
'~~~ (> O o)> ~~~~'
];
var index = Math.floor(Math.random() * emojis.length);
console.log(emojis[index]);
};
printLn();
printSpace(1);
printRandomEmoji();
printSpace(1);
printLn();
};
var printPrompt = function() {
console.log('(input)>>');
};
var collectInput = function(cb) {
setTimeout(function() {
cb('hihi');
}, 50);
};
var popTranslateQueue = function(queueObj) {
printSeparator();
printContext(queueObj);
printPrompt();
collectInput(function(input) {
outputTranslation(queueObj, input);
});
};
var outputTranslation = function(queueObj, input) {
console.log(queueObj.blob);
var path = queueObj.path;
var needle = queueObj.blob['en_US'];
console.log('the needle \n', needle, '\n in path', path);
};
shouldBegin.promise
.then(function() {
_.each(translateQueue, popTranslateQueue);
});

View file

@ -30,7 +30,7 @@ exports.sequenceInfo = {
}, },
about: { about: {
'en_US': 'A nicely paced introduction to the majority of git commands', 'en_US': 'A nicely paced introduction to the majority of git commands',
'f_FR': 'Une introduction en douceur à la majoité des commandes git', 'fr_FR': 'Une introduction en douceur à la majoité des commandes git',
'zh_CN': '一个节奏感良好的主流 Git 命令介绍', 'zh_CN': '一个节奏感良好的主流 Git 命令介绍',
'ko': '브랜치 관련 주요 git 명령어를 깔끔하게 알려드립니다' 'ko': '브랜치 관련 주요 git 명령어를 깔끔하게 알려드립니다'
} }