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/*"
script:
- make
- make po/starter-kit.pot

View file

@ -45,9 +45,9 @@ try {
}
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" },
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) {

View file

@ -26,9 +26,9 @@ try {
}
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" },
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) {
@ -70,11 +70,19 @@ function step() {
if (path.basename(filename) != "manifest.json")
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)
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();
});

View file

@ -46,10 +46,10 @@ function prepareHeader(header) {
}
/* A function for the front end */
statement = header["plural-forms"];
statement = header["plural-forms"];
if (statement[statement.length - 1] != ';')
statement += ';';
ret = 'function(n) {\nvar nplurals, plural;\n' + statement + '\nreturn plural;\n}';
ret = 'function(n) {\nvar nplurals, plural;\n' + statement + '\nreturn plural;\n}';
/* Added back in later */
delete header["plural-forms"];
@ -72,7 +72,7 @@ function prepareHeader(header) {
/* Parse and process the po data */
function parse() {
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;
if (err)
@ -117,7 +117,7 @@ function finish(data) {
if (opts.output) {
fs.writeFile(opts.output, data, function(err) {
if (err)
fatal(err.message);
fatal(err.message);
process.exit(0);
});
} else {