Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/pofiles #5

Merged
merged 6 commits into from
Mar 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions bin/bundle-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function showHelpAndExit() {
}

var argv = require('minimist')(process.argv.slice(2), {
string: 'toh',
alias: {t: 'translations', o: 'output', h: 'help'}
string: 'tohf',
alias: {t: 'translations', o: 'output', h: 'help', f: 'format'}
});

if (!(argv._.length && argv.t) || argv.h) {
Expand All @@ -25,11 +25,18 @@ var chalk = require('chalk');
var fs = require('fs');
var rw = require('rw');

var io = require('../build/io').default;
var filesFromMixedPaths = require('./filesFromMixedPaths');
var translateMessagesToBundle = require('../build/translate').default;

if (argv.f) {
var format = argv.f;
} else {
var fileChunks = argv.t.split('.');
var format = fileChunks[fileChunks.length - 1];
}

var translations = JSON.parse(rw.readFileSync(argv.t, "utf8"));
var translations = rw.readFileSync(argv.t, "utf8");
var files = filesFromMixedPaths(argv._);
var bundle = {};
var missing = {};
Expand All @@ -42,6 +49,7 @@ files.forEach(function (filename) {
} catch (e) {
console.error(chalk.bold.red("\nError in file " + filename + ":"));
console.error(e);
console.error(e.stack);
e.node && console.error(generate(e.node));
process.exit(1);
}
Expand Down
35 changes: 4 additions & 31 deletions bin/extract-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ require('babel-polyfill');
function showHelpAndExit() {
console.log("Usage: extract-messages [-m EXISTING] [-o OUTPUT] ...FILES/DIRECTORIES");
console.log("Prints a JSON document with messages in FILES/DIRECTORIES mapped to themselves.");
console.log("If -m is passed, merges with EXISTING translations.");
console.log("If -o is passed, writes to OUTPUT instead of stdout.");
process.exit();
}

var argv = require('minimist')(process.argv.slice(2), {
string: 'moh',
alias: {m: 'merge', o: 'output', h: 'help'}
string: 'oh',
alias: {o: 'output', h: 'help'}
});

if (argv._.length === 0 || argv.h) {
Expand All @@ -24,35 +23,9 @@ var chalk = require('chalk');
var fs = require('fs');

var filesFromMixedPaths = require('./filesFromMixedPaths');
var extractFromSource = require('../build/extract').extractFromSource;

var paths = filesFromMixedPaths(argv._);
var messages = {};

paths.forEach(function (path) {
var source = fs.readFileSync(path, "utf8");
try {
var messagesInFile = extractFromSource(source);
} catch (e) {
console.error(chalk.bold.red("\nError in file " + path + ":"));
console.error(e);
console.error(e.stack);
process.exit(1);
}
messagesInFile.forEach(function (message) {
messages[message] = message;
});
});

if (argv.m) {
var existing = JSON.parse(fs.readFileSync(argv.m, 'utf-8'));
Object.keys(existing).forEach(function(k) {
messages[k] = existing[k];
});
}

var output = JSON.stringify(messages, null, 2);
var extractFromPaths = require('../build/extract').default;

var output = extractFromPaths(argv._);
if (argv.o) {
fs.writeFileSync(argv.o, output);
} else {
Expand Down
Loading