From 806b101ec47f28d44ea4510035f0fa0c8b62a486 Mon Sep 17 00:00:00 2001 From: Tsvetomir Tsonev Date: Wed, 15 Feb 2017 18:07:36 +0200 Subject: [PATCH] feat: make the file a positional parameter BREAKING CHANGE: CLI syntax. See README. --- README.md | 4 ++-- bin/xlf-translate | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b2e037c..6606811 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ localized: ## Usage -`xlf-translate --lang-file=lang/fr.yml --messages-file=messages.fr.xlf` +`xlf-translate --lang-file sample/lang/fr.yml sample/messages.fr.xlf` This will populate all empty target elements in the `messages.xlf` file with matching translations. Non-empty target elements will be skipped to avoid overwriting user translations. @@ -55,7 +55,7 @@ This will populate all empty target elements in the `messages.xlf` file with mat You can also force overwriting all translations, regardless if empty or not: -`xlf-translate --lang-file=lang/fr.yml --messages-file=messages.fr.xlf --force` +`xlf-translate --force --lang-file sample/lang/fr.yml sample/messages.fr.xlf` ## See Also diff --git a/bin/xlf-translate b/bin/xlf-translate index 4668fc9..036b98c 100755 --- a/bin/xlf-translate +++ b/bin/xlf-translate @@ -9,23 +9,22 @@ const translate = require('../translate'); const args = (() => { const argparse = require('argparse'); const parser = new argparse.ArgumentParser({ - version: '0.1.0', + version: '1.0.0', addHelp: true, - description: 'xlf-translate populates translation files based on keys' + description: 'Looks-up translations based on unique keys' }); - parser.addArgument([ '-l', '--lang-file' ], { - help: 'file containing translations (YAML)', - required: true + parser.addArgument('file', { + help: 'XLIFF (.xlf) file to translate' }); - parser.addArgument([ '-m', '--messages-file' ], { - help: 'messages file to process', + parser.addArgument([ '-l', '--lang-file' ], { + help: 'YAML file containing translated messages', required: true }); parser.addArgument([ '-f', '--force' ], { - help: 'overwrites existing translations', + help: 'Overwrites existing translation targets', defaultValue: false, action: 'storeTrue' }); @@ -36,7 +35,7 @@ const args = (() => { const langData = fs.readFileSync(args.lang_file); const lang = yaml.safeLoad(langData); -const messageData = fs.readFileSync(args.messages_file); +const messageData = fs.readFileSync(args.file); const parser = new xml.Parser(); parser.parseString(messageData, (err, result) => { if (err) { @@ -49,7 +48,7 @@ parser.parseString(messageData, (err, result) => { const builder = new xml.Builder(); const out = builder.buildObject(result); - fs.writeFileSync(args.messages_file, out); + fs.writeFileSync(args.file, out); console.log(`Done. Replaced ${stats.count} units, skipped ${stats.skip}.`); });