UNPKG

arb-convert

Version:

Convert Application Resource Bundle (ARB) translation files to other translation formats and back

47 lines (46 loc) 1.61 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var commander_1 = __importDefault(require("commander")); var fs_1 = __importDefault(require("fs")); var index_1 = require("../index"); var program = new commander_1.default.Command(); program .name('xliff2arb') .option('--file <filename>', 'source XLIFF file (required)') .option('--sourceout <filename>', 'write source ARB to file if given or stdout if omitted') .option('--targetout <filename>', 'write target ARB to file if given') .parse(process.argv); // No params if (process.argv.length <= 2) { program.help(); // shows help and exits } try { var options = program.opts(); if (!options.file) { throw new Error("option '--file <filename>' is required"); } var fileContent = fs_1.default.readFileSync(options.file, 'utf8'); var result = index_1.parseToArb('xliff', { content: fileContent, }); if (options.sourceout) { fs_1.default.writeFileSync(options.sourceout, result.source); } else { process.stdout.write(result.source); } if (options.targetout && !result.target) { process.stdout.write('warn: no target strings found in source file'); } if (options.targetout && result.target) { fs_1.default.writeFileSync(options.targetout, result.target); } } catch (error) { process.stdout.write("error: " + error.message); process.exit(1); }