Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 98 lines (83 sloc) 3.326 kB
#!/usr/bin/env node
var async = require('async'),
exec = require('child_process').exec,
path = require('path'),
util = require('util');
// ./scripts/extract-pot --locale locale server static
// Given a locale directory to write out pot files and
// 1 or more directories to find sources in, run
// .js and template (.ejs) files through jsxgettext
var argv = require('optimist').demand(['l'])
.usage('Extract gettext strings from codebase. Usage: $0 --locale=DIRECTORY INPUT_DIR [INPUT_DIR]*')
.alias('h', 'help')
.describe('h', 'display this usage message')
.alias('l', 'locale')
.describe('l', 'locale directory where pot and po files will be written')
//.alias('e', 'exclude')
.describe('exclude', 'directory or filename pattern to exclude from jsxgettext\n\t\tmay be used multiple times')
.alias('t', 'template-engine')
.default('t', 'ejs')
.describe('template-engine', 'Template engine. Defaults to EJS, Jinja supported for nunjucks')
.alias('f', 'template-file-ext')
.default('f', 'ejs')
.describe('template-file-ext', 'File extension of templates. Defaults to ejs as in home.ejs, value can be valid file ext.')
.check(function (argv) {
// We have atleast one directory of source code to process
return argv._.length >= 1;
})
.argv;
var localeDir = path.resolve(process.cwd(), argv.locale);
var sourceDirs = [];
argv._.forEach(function (dir) {
sourceDirs.push(path.resolve(process.cwd(), dir));
});
// top of repo is our current working directory
process.chdir(path.dirname(__dirname));
var jsxGettextPath = path.join(__dirname, '../node_modules/.bin/jsxgettext');
var jsCmd = jsxGettextPath + ' %s --keyword=_ -l JavaScript ' +
'--output-dir=%s/templates/LC_MESSAGES --from-code=utf-8 --output=messages.pot ' +
'`find %s -name \'*.js\' | grep -v node_modules | grep -v .git';
var templateCmd = jsxGettextPath + ' %s --keyword=_ -L ' + argv['template-engine'] +
' --output-dir=%s/templates/LC_MESSAGES --from-code=utf-8 --output=messages.pot ' +
'`find %s -name \'*.%s\' | grep -v node_modules | grep -v .git';
if (argv.exclude) {
var excludes = argv.exclude;
if ('string' === typeof argv.exclude) {
excludes = [argv.exclude];
}
excludes.forEach(function (exclude) {
jsCmd += ' | grep -v ' + exclude;
templateCmd += ' | grep -v ' + exclude;
});
}
templateExt = argv['template-file-ext'];
// Close out `find ...` backtick
jsCmd += '`';
templateCmd += '`';
// Create a new .pot file
var dashJ = '';
// Run commands
async.forEachSeries(sourceDirs, function (dir) {
exec(util.format(jsCmd, dashJ, localeDir, dir), function (err, stdout, stderr) {
// Join existing pot file
dashJ = ' --join-existing=true ';
// We expect an error if no gettext strings are used in client side code
if (err && stdout.indexOf('input argument is required') === -1) {
console.error(stdout);
console.error(stderr);
} else {
console.log(util.format(templateCmd, dashJ, localeDir, dir, templateExt));
exec(util.format(templateCmd, dashJ, localeDir, dir, templateExt), function (err, stdout, stderr) {
if (err) {
console.error(stdout);
console.error(stderr);
}
console.log('done');
});
}
});
}, function (err) {
if (err) {
console.error(err);
}
});
Jump to Line
Something went wrong with that request. Please try again.