noVNC/po/po2js

42 lines
1.3 KiB
JavaScript
Executable File

#!/usr/bin/env node
/*
* ps2js: gettext .po to noVNC .js converter
* Copyright (C) 2018 The noVNC authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const { program } = require('commander');
const fs = require('fs');
const po2json = require("po2json");
program
.argument('<input>')
.argument('<output>')
.parse(process.argv);
const data = po2json.parseFileSync(program.args[0]);
const bodyPart = Object.keys(data)
.filter(msgid => msgid !== "")
.filter(msgid => data[msgid][1] !== "")
.map((msgid) => {
const msgstr = data[msgid][1];
return " " + JSON.stringify(msgid) + ": " + JSON.stringify(msgstr);
}).join(",\n");
const output = "{\n" + bodyPart + "\n}";
fs.writeFileSync(program.args[1], output);