Fix building PO template

The current version failed with

    Option "--directory" requires 1 arguments, but 0 were provided

In the current stdio npm module version, getopt() now requires a
`default:` attribute, otherwise it considers the options as required.

Also sync PO helpers with current cockpit.

Add PO template build to travis check, to make sure that it keeps
working.

Closes #375
This commit is contained in:
Martin Pitt 2020-09-29 12:04:13 +02:00 committed by Marius Vollmer
parent 6f8cd78783
commit cbedf06704
4 changed files with 19 additions and 10 deletions

View file

@ -5,3 +5,4 @@ node_js:
- "lts/*" - "lts/*"
script: script:
- make - make
- make po/starter-kit.pot

View file

@ -45,9 +45,9 @@ try {
} }
var opts = stdio.getopt({ var opts = stdio.getopt({
directory: { key: "d", args: 1, description: "Base directory for input files" }, directory: { key: "d", args: 1, description: "Base directory for input files", default: "." },
output: { key: "o", args: 1, description: "Output file" }, output: { key: "o", args: 1, description: "Output file" },
from: { key: "f", args: 1, description: "File containing list of input files" }, from: { key: "f", args: 1, description: "File containing list of input files", default: "" },
}); });
if (!opts.from && opts.args.length < 1) { if (!opts.from && opts.args.length < 1) {

View file

@ -26,9 +26,9 @@ try {
} }
var opts = stdio.getopt({ var opts = stdio.getopt({
directory: { key: "d", args: 1, description: "Base directory for input files" }, directory: { key: "d", args: 1, description: "Base directory for input files", default: "." },
output: { key: "o", args: 1, description: "Output file" }, output: { key: "o", args: 1, description: "Output file" },
from: { key: "f", args: 1, description: "File containing list of input files" }, from: { key: "f", args: 1, description: "File containing list of input files", default: "" },
}); });
if (!opts.from && opts.args.length < 1) { if (!opts.from && opts.args.length < 1) {
@ -70,11 +70,19 @@ function step() {
if (path.basename(filename) != "manifest.json") if (path.basename(filename) != "manifest.json")
return step(); return step();
fs.readFile(filename, { encoding: "utf-8"}, function(err, data) { /* Qualify the filename if necessary */
var full = filename;
if (opts.directory)
full = path.join(opts.directory, filename);
fs.readFile(full, { encoding: "utf-8"}, function(err, data) {
if (err) if (err)
fatal(err.message); fatal(err.message);
process_manifest(JSON.parse(data)); // There are variables which when not substituted can cause JSON.parse to fail
// Dummy replace them. None variable is going to be translated anyway
safe_data = data.replace(/\@.+?\@/gi, 1);
process_manifest(JSON.parse(safe_data));
return step(); return step();
}); });

View file

@ -72,7 +72,7 @@ function prepareHeader(header) {
/* Parse and process the po data */ /* Parse and process the po data */
function parse() { function parse() {
filename = opts.args[0]; filename = opts.args[0];
po2json.parseFile(opts.args[0], { "fuzzy": true }, function(err, jsonData) { po2json.parseFile(opts.args[0], { "fuzzy": false }, function(err, jsonData) {
var plurals, pos; var plurals, pos;
if (err) if (err)