Skip to content

Commit

Permalink
feat: make the file a positional parameter
Browse files Browse the repository at this point in the history
BREAKING CHANGE: CLI syntax. See README.
  • Loading branch information
tsvetomir committed Feb 15, 2017
1 parent e94148f commit 806b101
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ 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.

> The messages file will be updated in place.

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

Expand Down
19 changes: 9 additions & 10 deletions bin/xlf-translate
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
Expand All @@ -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) {
Expand All @@ -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}.`);
});

0 comments on commit 806b101

Please sign in to comment.