Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
05d1917f9d | ||
|
e50d52003b | ||
|
cb8731ee0f | ||
|
9908681243 | ||
|
a83123fb12 | ||
|
6b740867d6 |
@@ -15,7 +15,7 @@ Add a script to your project's `package.json`:
|
||||
```json
|
||||
...
|
||||
"scripts": {
|
||||
"extract-i18n": "ngx-translate-extract --input ./src --output ./src/assets/i18n/ --clean --sort --format namespaced-json"
|
||||
"extract-i18n": "ngx-translate-extract --input ./src --output ./src/assets/i18n/strings.json --key-as-default-value --clean --sort --format namespaced-json"
|
||||
}
|
||||
...
|
||||
```
|
||||
@@ -25,11 +25,11 @@ You can now run `npm run extract-i18n` and it will extract strings from your pro
|
||||
|
||||
**Extract from dir and save to file**
|
||||
|
||||
`ngx-translate-extract --input ./src --output ./src/assets/i18n/template.json`
|
||||
`ngx-translate-extract --input ./src --output ./src/assets/i18n/strings.json`
|
||||
|
||||
**Extract from multiple dirs**
|
||||
|
||||
`ngx-translate-extract --input ./src-a ./src-b --output ./src/assets/i18n/template.json`
|
||||
`ngx-translate-extract --input ./src-a ./src-b --output ./src/assets/i18n/strings.json`
|
||||
|
||||
|
||||
**Extract and save to multiple files using path expansion**
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@biesbjerg/ngx-translate-extract",
|
||||
"version": "6.0.1",
|
||||
"version": "6.0.3",
|
||||
"description": "Extract strings from projects using ngx-translate",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import * as yargs from 'yargs';
|
||||
import { red, green } from 'colorette';
|
||||
|
||||
import { ExtractTask } from './tasks/extract.task';
|
||||
import { ParserInterface } from '../parsers/parser.interface';
|
||||
@@ -148,6 +149,13 @@ const compiler: CompilerInterface = CompilerFactory.create(cli.format, {
|
||||
});
|
||||
extractTask.setCompiler(compiler);
|
||||
|
||||
extractTask.execute();
|
||||
|
||||
console.log(donateMessage);
|
||||
// Run task
|
||||
try {
|
||||
extractTask.execute();
|
||||
console.log(green('\nDone.\n'));
|
||||
console.log(donateMessage);
|
||||
process.exit(0);
|
||||
} catch (e) {
|
||||
console.log(red(`\nAn error occurred: ${e}\n`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ import { ParserInterface } from '../../parsers/parser.interface';
|
||||
import { PostProcessorInterface } from '../../post-processors/post-processor.interface';
|
||||
import { CompilerInterface } from '../../compilers/compiler.interface';
|
||||
|
||||
import { cyan, green, bold, dim } from 'colorette';
|
||||
import { cyan, green, bold, dim, red } from 'colorette';
|
||||
import * as glob from 'glob';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
@@ -56,26 +56,33 @@ export class ExtractTask implements TaskInterface {
|
||||
|
||||
let existing: TranslationCollection = new TranslationCollection();
|
||||
if (!this.options.replace && fs.existsSync(outputPath)) {
|
||||
existing = this.compiler.parse(fs.readFileSync(outputPath, 'utf-8'));
|
||||
try {
|
||||
existing = this.compiler.parse(fs.readFileSync(outputPath, 'utf-8'));
|
||||
} catch (e) {
|
||||
this.out(`%s %s`, dim(`- ${outputPath}`), red(`[ERROR]`));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// merge extracted strings with existing
|
||||
const draft = extracted.union(existing);
|
||||
|
||||
if (existing.isEmpty()) {
|
||||
this.out(dim(`- ${outputPath}`));
|
||||
} else {
|
||||
this.out(dim(`- ${outputPath} (merged)`));
|
||||
}
|
||||
|
||||
// Run collection through post processors
|
||||
const final = this.process(draft, extracted, existing);
|
||||
|
||||
// Save to file
|
||||
this.save(outputPath, final);
|
||||
// Save
|
||||
try {
|
||||
let event = 'CREATED';
|
||||
if (fs.existsSync(outputPath)) {
|
||||
this.options.replace ? event = 'REPLACED' : event = 'MERGED';
|
||||
}
|
||||
this.save(outputPath, final);
|
||||
this.out(`%s %s`, dim(`- ${outputPath}`), green(`[${event}]`));
|
||||
} catch (e) {
|
||||
this.out(`%s %s`, dim(`- ${outputPath}`), red(`[ERROR]`));
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
this.out(green('\nDone.\n'));
|
||||
}
|
||||
|
||||
public setParsers(parsers: ParserInterface[]): this {
|
||||
|
Reference in New Issue
Block a user