po2js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env node
  2. /*
  3. * ps2js: gettext .po to noVNC .js converter
  4. * Copyright (C) 2018 The noVNC Authors
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. const getopt = require('node-getopt');
  20. const fs = require('fs');
  21. const po2json = require("po2json");
  22. const opt = getopt.create([
  23. ['h', 'help', 'display this help'],
  24. ]).bindHelp().parseSystem();
  25. if (opt.argv.length != 2) {
  26. console.error("Incorrect number of arguments given");
  27. process.exit(1);
  28. }
  29. const data = po2json.parseFileSync(opt.argv[0]);
  30. const bodyPart = Object.keys(data).filter(msgid => msgid !== "").map((msgid) => {
  31. if (msgid === "") return;
  32. const msgstr = data[msgid][1];
  33. return " " + JSON.stringify(msgid) + ": " + JSON.stringify(msgstr);
  34. }).join(",\n");
  35. const output = "{\n" + bodyPart + "\n}";
  36. fs.writeFileSync(opt.argv[1], output);