Improved --translate feature.
This commit is contained in:
parent
4e8ae05c2b
commit
04caa8bd1c
|
@ -183,10 +183,18 @@ function CreateMeshCentralServer(config, args) {
|
|||
for (var i in files) {
|
||||
var file = obj.path.join(obj.webViewsOverridePath, files[i]);
|
||||
if (file.endsWith('.handlebars') && !file.endsWith('-min.handlebars')) {
|
||||
translateEngine.startEx(['', '', 'minify', file]);
|
||||
}
|
||||
}
|
||||
files = obj.fs.readdirSync(obj.webViewsOverridePath);
|
||||
for (var i in files) {
|
||||
var file = obj.path.join(obj.webViewsOverridePath, files[i]);
|
||||
if (file.endsWith('.handlebars') || file.endsWith('-min.handlebars')) {
|
||||
translateEngine.startEx(['', '', 'translate', '*', translationFile, file, '--subdir:translations']);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (obj.webPublicOverridePath != null) {
|
||||
didSomething = true;
|
||||
var files = obj.fs.readdirSync(obj.webPublicOverridePath);
|
||||
|
@ -197,6 +205,7 @@ function CreateMeshCentralServer(config, args) {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (didSomething == false) { console.log("Nothing to do."); }
|
||||
process.exit();
|
||||
|
|
|
@ -99,7 +99,7 @@ function startEx(argv) {
|
|||
|
||||
var command = null;
|
||||
if (argv.length > 2) { command = argv[2].toLowerCase(); }
|
||||
if (['check', 'extract', 'extractall', 'translate', 'translateall', 'minifyall', 'merge', 'totext', 'fromtext'].indexOf(command) == -1) { command = null; }
|
||||
if (['minify', 'check', 'extract', 'extractall', 'translate', 'translateall', 'minifyall', 'merge', 'totext', 'fromtext'].indexOf(command) == -1) { command = null; }
|
||||
|
||||
if (directRun) { log('MeshCentral web site translator'); }
|
||||
if (command == null) {
|
||||
|
@ -283,6 +283,42 @@ function startEx(argv) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (command == 'minify') {
|
||||
var outname = argv[3];
|
||||
var outnamemin = null;
|
||||
if (outname.endsWith('.handlebars')) {
|
||||
outnamemin = (outname.substring(0, outname.length - 11) + '-min.handlebars');
|
||||
} else if (outname.endsWith('.html')) {
|
||||
outnamemin = (outname.substring(0, outname.length - 5) + '-min.html');
|
||||
} else if (outname.endsWith('.htm')) {
|
||||
outnamemin = (outname.substring(0, outname.length - 4) + '-min.htm');
|
||||
} else {
|
||||
outnamemin = (outname, outname + '.min');
|
||||
}
|
||||
log('Generating ' + path.basename(outnamemin) + '...');
|
||||
|
||||
// Minify the file
|
||||
if (minifyLib = 2) {
|
||||
var minifiedOut = minify(fs.readFileSync(outname).toString(), {
|
||||
collapseBooleanAttributes: true,
|
||||
collapseInlineTagWhitespace: false, // This is not good.
|
||||
collapseWhitespace: true,
|
||||
minifyCSS: true,
|
||||
minifyJS: true,
|
||||
removeComments: true,
|
||||
removeOptionalTags: true,
|
||||
removeEmptyAttributes: true,
|
||||
removeAttributeQuotes: true,
|
||||
removeRedundantAttributes: true,
|
||||
removeScriptTypeAttributes: true,
|
||||
removeTagWhitespace: true,
|
||||
preserveLineBreaks: false,
|
||||
useShortDoctype: true
|
||||
});
|
||||
fs.writeFileSync(outnamemin, minifiedOut, { flag: 'w+' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -474,7 +510,7 @@ function extract(langFile, sources) {
|
|||
}
|
||||
fs.writeFileSync(langFile, translationsToJson({ strings: output }), { flag: 'w+' });
|
||||
log(format("{0} strings in output file.", count));
|
||||
process.exit();
|
||||
//process.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue