taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

po2ts (1297B)


      1 #!/usr/bin/env node
      2 /*
      3  This file is part of GNU Taler
      4  (C) 2020 Taler Systems S.A.
      5 
      6  GNU Taler is free software; you can redistribute it and/or modify it under the
      7  terms of the GNU General Public License as published by the Free Software
      8  Foundation; either version 3, or (at your option) any later version.
      9 
     10  GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
     11  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     12  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     13 
     14  You should have received a copy of the GNU General Public License along with
     15  GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     16  */
     17 
     18 /**
     19  * Convert a <lang>.po file into a JavaScript / TypeScript expression.
     20  */
     21 
     22 const po2json = require("po2json");
     23 
     24 const filename = process.argv[2];
     25 
     26 if (!filename) {
     27   console.error("error: missing filename");
     28   process.exit(1);
     29 }
     30 
     31 const m = filename.match(/([a-zA-Z0-9-_]+).po/);
     32 
     33 if (!m) {
     34   console.error("error: unexpected filename (expected <lang>.po)");
     35   process.exit(1);
     36 }
     37 
     38 const lang = m[1];
     39 const pojson = po2json.parseFileSync(filename, { format: "jed1.x", fuzzy: true });
     40 const s =
     41   "strings['" + lang + "'] = " + JSON.stringify(pojson, null, "  ") + ";\n";
     42 console.log(s);