Update README and CLI output
This commit is contained in:
23
README.md
23
README.md
@@ -1,31 +1,22 @@
|
|||||||
# ng2-translate-extract
|
# ng2-translate-extract
|
||||||
Extract strings from projects using ng2-translate to json or pot files.
|
Extract translatable (ng2-translate) strings and save as a JSON or Gettext pot file.
|
||||||
|
Merges with existing strings if the output file already exists.
|
||||||
**THIS IS STILL VERY MUCH A WORK IN PROGRESS**
|
|
||||||
|
|
||||||
## Usage
|
## 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`
|
`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": {
|
"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.
|
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.
|
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
|
## Commandline arguments
|
||||||
```
|
```
|
||||||
Usage:
|
Usage:
|
||||||
@@ -37,7 +28,7 @@ Options:
|
|||||||
strings (Default is current directory)
|
strings (Default is current directory)
|
||||||
-f, --format [VALUE] Output format. VALUE must be either [json|pot] (Default is json)
|
-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
|
-r, --replace BOOLEAN Replace the contents of output file if it exists
|
||||||
(merging by default)
|
(Merges by default)
|
||||||
-c, --clean BOOLEAN Remove unused keys when merging
|
-c, --clean BOOLEAN Remove obsolete strings when merging
|
||||||
-h, --help Display help and usage details
|
-h, --help Display help and usage details
|
||||||
```
|
```
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@biesbjerg/ng2-translate-extract",
|
"name": "@biesbjerg/ng2-translate-extract",
|
||||||
"version": "0.2.9",
|
"version": "0.3",
|
||||||
"description": "Extract strings from projects using ng2-translate",
|
"description": "Extract strings from projects using ng2-translate",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
|
@@ -15,8 +15,8 @@ const options = cli.parse({
|
|||||||
dir: ['d', 'Directory path you would like to extract strings from', 'dir', process.env.PWD],
|
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],
|
output: ['o', 'Directory path you would like to save extracted strings to', 'dir', process.env.PWD],
|
||||||
format: ['f', 'Output format', ['json', 'pot'], 'json'],
|
format: ['f', 'Output format', ['json', 'pot'], 'json'],
|
||||||
replace: ['r', 'Replace the contents of output file if it exists (merging by default)', 'boolean', false],
|
replace: ['r', 'Replace the contents of output file if it exists (Merges by default)', 'boolean', false],
|
||||||
clean: ['c', 'Remove unused keys when merging', 'boolean', false]
|
clean: ['c', 'Remove obsolete strings when merging', 'boolean', false]
|
||||||
});
|
});
|
||||||
|
|
||||||
[options.dir, options.output].forEach(dir => {
|
[options.dir, options.output].forEach(dir => {
|
||||||
@@ -42,6 +42,7 @@ const patterns: string[] = [
|
|||||||
try {
|
try {
|
||||||
const extractor: Extractor = new Extractor(parsers, patterns);
|
const extractor: Extractor = new Extractor(parsers, patterns);
|
||||||
cli.info(`Extracting strings from '${options.dir}'`);
|
cli.info(`Extracting strings from '${options.dir}'`);
|
||||||
|
|
||||||
const extracted: TranslationCollection = extractor.process(options.dir);
|
const extracted: TranslationCollection = extractor.process(options.dir);
|
||||||
cli.ok(`* Extracted ${extracted.count()} strings`);
|
cli.ok(`* Extracted ${extracted.count()} strings`);
|
||||||
|
|
||||||
@@ -54,10 +55,9 @@ try {
|
|||||||
|
|
||||||
if (!options.replace && fs.existsSync(dest)) {
|
if (!options.replace && fs.existsSync(dest)) {
|
||||||
const existing: TranslationCollection = compiler.parse(fs.readFileSync(dest, 'utf-8'));
|
const existing: TranslationCollection = compiler.parse(fs.readFileSync(dest, 'utf-8'));
|
||||||
|
|
||||||
if (existing.count() > 0) {
|
if (existing.count() > 0) {
|
||||||
collection = extracted.union(existing);
|
collection = extracted.union(existing);
|
||||||
cli.ok(`* Merged ${existing.count()} existing strings`);
|
cli.ok(`* Merged with ${existing.count()} existing strings`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.clean) {
|
if (options.clean) {
|
||||||
@@ -65,7 +65,7 @@ try {
|
|||||||
collection = collection.intersect(extracted);
|
collection = collection.intersect(extracted);
|
||||||
const removeCount = collectionCount - collection.count();
|
const removeCount = collectionCount - collection.count();
|
||||||
if (removeCount > 0) {
|
if (removeCount > 0) {
|
||||||
cli.ok(`* Removed ${removeCount} unused strings`);
|
cli.ok(`* Removed ${removeCount} obsolete strings`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user