Update README and CLI output

This commit is contained in:
Kim Biesbjerg
2016-12-20 16:02:56 +01:00
parent 48be895dd4
commit c88d387516
3 changed files with 13 additions and 22 deletions

View File

@@ -1,31 +1,22 @@
# ng2-translate-extract
Extract strings from projects using ng2-translate to json or pot files.
**THIS IS STILL VERY MUCH A WORK IN PROGRESS**
Extract translatable (ng2-translate) strings and save as a JSON or Gettext pot file.
Merges with existing strings if the output file already exists.
## Usage
If you only need to extract strings from one project, you can install the package locally:
Install the package in your project:
`npm install @biesbjerg/ng2-translate-extract --save-dev`
Add the following `extract` script your project's `package.json`:
Add an `extract` script to your project's `package.json`:
```
"scripts": {
"extract": "ng2-translate-extract --dir ./src --output ./ --format=json"
"extract": "ng2-translate-extract --dir ./src --output ./ --format=json --clean"
}
```
You can now run `npm run extract` to extract strings from your project's `src` dir. The extracted strings are saved in `JSON`-format in your project's root.
Modify the scripts arguments as required.
## Global install
You can also install the package globally:
`npm install @biesbjerg/ng2-translate-extract -g`
Now you can execute the script from everywhere:
`ng2-translate-extract --dir /extract/from/this/dir --output /save/to/this/dir --format json --clean`
## Commandline arguments
```
Usage:
@@ -37,7 +28,7 @@ Options:
strings (Default is current directory)
-f, --format [VALUE] Output format. VALUE must be either [json|pot] (Default is json)
-r, --replace BOOLEAN Replace the contents of output file if it exists
(merging by default)
-c, --clean BOOLEAN Remove unused keys when merging
(Merges by default)
-c, --clean BOOLEAN Remove obsolete strings when merging
-h, --help Display help and usage details
```

View File

@@ -1,6 +1,6 @@
{
"name": "@biesbjerg/ng2-translate-extract",
"version": "0.2.9",
"version": "0.3",
"description": "Extract strings from projects using ng2-translate",
"main": "dist/index.js",
"typings": "dist/index.d.ts",

View File

@@ -15,8 +15,8 @@ const options = cli.parse({
dir: ['d', 'Directory path you would like to extract strings from', 'dir', process.env.PWD],
output: ['o', 'Directory path you would like to save extracted strings to', 'dir', process.env.PWD],
format: ['f', 'Output format', ['json', 'pot'], 'json'],
replace: ['r', 'Replace the contents of output file if it exists (merging by default)', 'boolean', false],
clean: ['c', 'Remove unused keys when merging', 'boolean', false]
replace: ['r', 'Replace the contents of output file if it exists (Merges by default)', 'boolean', false],
clean: ['c', 'Remove obsolete strings when merging', 'boolean', false]
});
[options.dir, options.output].forEach(dir => {
@@ -42,6 +42,7 @@ const patterns: string[] = [
try {
const extractor: Extractor = new Extractor(parsers, patterns);
cli.info(`Extracting strings from '${options.dir}'`);
const extracted: TranslationCollection = extractor.process(options.dir);
cli.ok(`* Extracted ${extracted.count()} strings`);
@@ -54,10 +55,9 @@ try {
if (!options.replace && fs.existsSync(dest)) {
const existing: TranslationCollection = compiler.parse(fs.readFileSync(dest, 'utf-8'));
if (existing.count() > 0) {
collection = extracted.union(existing);
cli.ok(`* Merged ${existing.count()} existing strings`);
cli.ok(`* Merged with ${existing.count()} existing strings`);
}
if (options.clean) {
@@ -65,7 +65,7 @@ try {
collection = collection.intersect(extracted);
const removeCount = collectionCount - collection.count();
if (removeCount > 0) {
cli.ok(`* Removed ${removeCount} unused strings`);
cli.ok(`* Removed ${removeCount} obsolete strings`);
}
}
}