Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
bf3b1b29bf | ||
|
0f0f277a08 | ||
|
994c31fb97 | ||
|
f590b9bb9e | ||
|
d51674950c | ||
|
931433e83d |
13
README.md
13
README.md
@@ -1,16 +1,18 @@
|
||||
# ng2-translate-extract
|
||||
Extract translatable (ng2-translate) strings and save as a JSON or Gettext pot file.
|
||||
If you like this project please show your support with a GitHub star. Much appreciated!
|
||||
|
||||
# ngx-translate-extract
|
||||
Extract translatable (ngx-translate) strings and save as a JSON or Gettext pot file.
|
||||
Merges with existing strings if the output file already exists.
|
||||
|
||||
## Usage
|
||||
Install the package in your project:
|
||||
|
||||
`npm install @biesbjerg/ng2-translate-extract --save-dev`
|
||||
`npm install @biesbjerg/ngx-translate-extract --save-dev`
|
||||
|
||||
Add an `extract` script to your project's `package.json`:
|
||||
```
|
||||
"scripts": {
|
||||
"extract": "ng2-translate-extract --dir ./src --output ./ --format=json --clean"
|
||||
"extract": "ngx-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.
|
||||
@@ -20,7 +22,7 @@ Modify the scripts arguments as required.
|
||||
## Commandline arguments
|
||||
```
|
||||
Usage:
|
||||
ng2-translate-extract [OPTIONS] [ARGS]
|
||||
ngx-translate-extract [OPTIONS] [ARGS]
|
||||
|
||||
Options:
|
||||
-d, --dir [DIR] Directory path you would like to extract strings from (Default is current directory)
|
||||
@@ -33,5 +35,6 @@ Options:
|
||||
-s, --sort BOOLEAN Sort translations in the output file in alphabetical
|
||||
order
|
||||
-c, --clean BOOLEAN Remove obsolete strings when merging
|
||||
-e, --experimental BOOLEAN Use experimental AST Service Parser
|
||||
-h, --help Display help and usage details
|
||||
```
|
||||
|
32
package.json
32
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@biesbjerg/ng2-translate-extract",
|
||||
"version": "0.6.0",
|
||||
"description": "Extract strings from projects using ng2-translate",
|
||||
"name": "@biesbjerg/ngx-translate-extract",
|
||||
"version": "1.0.0",
|
||||
"description": "Extract strings from projects using ngx-translate",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"files": [
|
||||
@@ -9,7 +9,7 @@
|
||||
"dist/"
|
||||
],
|
||||
"bin": {
|
||||
"ng2-translate-extract": "bin/extract.js"
|
||||
"ngx-translate-extract": "bin/extract.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run clean && tsc",
|
||||
@@ -20,45 +20,49 @@
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/biesbjerg/ng2-translate-extract.git"
|
||||
"url": "https://github.com/biesbjerg/ngx-translate-extract.git"
|
||||
},
|
||||
"keywords": [
|
||||
"angular",
|
||||
"angular2",
|
||||
"ionic",
|
||||
"ionic2",
|
||||
"ng2-translate",
|
||||
"ngx-translate",
|
||||
"extract",
|
||||
"extractor",
|
||||
"translate",
|
||||
"translation",
|
||||
"i18n",
|
||||
"gettext"
|
||||
],
|
||||
"author": "Kim Biesbjerg <kim@biesbjerg.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/biesbjerg/ng2-translate-extract/issues"
|
||||
"url": "https://github.com/biesbjerg/ngx-translate-extract/issues"
|
||||
},
|
||||
"homepage": "https://github.com/biesbjerg/ng2-translate-extract",
|
||||
"homepage": "https://github.com/biesbjerg/ngx-translate-extract",
|
||||
"engines": {
|
||||
"node": ">=4.3.2"
|
||||
},
|
||||
"config": {},
|
||||
"devDependencies": {
|
||||
"@types/chai": "3.4.34",
|
||||
"@types/chai": "3.4.35",
|
||||
"@types/cheerio": "0.17.31",
|
||||
"@types/glob": "5.0.30",
|
||||
"@types/mocha": "2.2.34",
|
||||
"@types/mocha": "2.2.39",
|
||||
"chai": "3.5.0",
|
||||
"mocha": "3.2.0",
|
||||
"ts-node": "1.7.2",
|
||||
"tslint": "4.1.1",
|
||||
"tslint-eslint-rules": "3.2.0",
|
||||
"typescript": "2.0.10"
|
||||
"ts-node": "2.1.0",
|
||||
"tslint": "4.5.1",
|
||||
"tslint-eslint-rules": "3.4.0",
|
||||
"typescript": "2.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"cheerio": "0.22.0",
|
||||
"cli": "1.0.1",
|
||||
"fs": "0.0.1-security",
|
||||
"gettext-parser": "1.2.1",
|
||||
"gettext-parser": "1.2.2",
|
||||
"glob": "7.1.1",
|
||||
"path": "0.12.7",
|
||||
"flat": "2.0.1"
|
||||
|
@@ -34,7 +34,7 @@ export class AstServiceParser implements ParserInterface {
|
||||
}
|
||||
|
||||
protected _createSourceFile(path: string, contents: string): ts.SourceFile {
|
||||
return ts.createSourceFile(path, contents, ts.ScriptTarget.ES6, /*setParentNodes */ false);
|
||||
return ts.createSourceFile(path, contents, null, /*setParentNodes */ false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,6 +43,10 @@ export class AstServiceParser implements ParserInterface {
|
||||
*/
|
||||
protected _getInstancePropertyName(): string {
|
||||
const constructorNode = this._findConstructorNode();
|
||||
if (!constructorNode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const result = constructorNode.parameters.find(parameter => {
|
||||
// Skip if visibility modifier is not present (we want it set as an instance property)
|
||||
if (!parameter.modifiers) {
|
||||
@@ -50,7 +54,7 @@ export class AstServiceParser implements ParserInterface {
|
||||
}
|
||||
|
||||
// Make sure className is of the correct type
|
||||
const className: string = ( (parameter.type as ts.TypeReferenceNode).typeName as ts.Identifier).text;
|
||||
const className: string = ((parameter.type as ts.TypeReferenceNode).typeName as ts.Identifier).text;
|
||||
if (className !== this._serviceClassName) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -76,16 +76,11 @@ export class TranslationCollection {
|
||||
}
|
||||
|
||||
public sort(compareFn?: (a: string, b: string) => number): TranslationCollection {
|
||||
if (!compareFn) {
|
||||
// if no compare functions is provided use a case insensitive sorting function
|
||||
compareFn = (a, b) => a.toLowerCase().localeCompare(b.toLowerCase());
|
||||
}
|
||||
|
||||
let collection = new TranslationCollection();
|
||||
let sortedKeys = this.keys().sort(compareFn);
|
||||
sortedKeys.forEach((key) => {
|
||||
collection = collection.add(key, this.get(key));
|
||||
let values: TranslationType = {};
|
||||
this.keys().sort(compareFn).forEach((key) => {
|
||||
values[key] = this.get(key);
|
||||
});
|
||||
return collection;
|
||||
|
||||
return new TranslationCollection(values);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user