Compare commits

..

6 Commits

Author SHA1 Message Date
Kim Biesbjerg
677d2a35ca Update dependencies. Bump version 2017-04-06 08:52:22 +02:00
cvaliere
262a89206d fix parser regexp (#31)
- fix template parser regexp (Closes #15)
2017-04-06 08:50:23 +02:00
Kim Biesbjerg
bcb4a9c069 Fix bug where obsolete strings were not removed when --clean was used. Closes #29 2017-03-31 08:31:14 +02:00
Kim Biesbjerg
5ad1fe6a18 Remove unused import 2017-03-31 08:21:28 +02:00
Kim Biesbjerg
bc5ce7e80d Add marker argument to readme 2017-03-30 14:42:03 +02:00
Kim Biesbjerg
030ab145d6 Add return types 2017-03-30 14:40:51 +02:00
8 changed files with 21 additions and 15 deletions

View File

@@ -82,6 +82,8 @@ Options:
--output, -o Paths where you would like to save extracted
strings. You can use path expansion, glob patterns
and multiple paths [array] [required]
--marker, -m Extract strings passed to a marker function
[string] [default: false]
--format, -f Output format
[string] [choices: "json", "namespaced-json", "pot"] [default: "json"]
--format-indentation, --fi Output format indentation [string] [default: "\t"]

View File

@@ -1,6 +1,6 @@
{
"name": "@biesbjerg/ngx-translate-extract",
"version": "2.2.0",
"version": "2.2.2",
"description": "Extract strings from projects using ngx-translate",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
@@ -58,8 +58,8 @@
"chai": "3.5.0",
"mocha": "3.2.0",
"ts-node": "3.0.2",
"tslint": "4.5.1",
"tslint-eslint-rules": "3.5.1",
"tslint": "5.0.0",
"tslint-eslint-rules": "4.0.0",
"typescript": "2.2.2"
},
"dependencies": {

View File

@@ -104,7 +104,7 @@ export class ExtractTask implements TaskInterface {
if (this._options.clean) {
const collectionCount = processedCollection.count();
processedCollection = processedCollection.intersect(processedCollection);
processedCollection = processedCollection.intersect(collection);
const removeCount = collectionCount - processedCollection.count();
if (removeCount > 0) {
this._out(chalk.dim('- removed %d obsolete strings'), removeCount);

View File

@@ -48,7 +48,11 @@ export abstract class AbstractAstParser {
}, initialValue);
}
protected _printAllChildren(sourceFile: ts.SourceFile, node: ts.Node, depth = 0) {
protected _syntaxKindToName(kind: ts.SyntaxKind): string {
return ts.SyntaxKind[kind];
}
protected _printAllChildren(sourceFile: ts.SourceFile, node: ts.Node, depth = 0): void {
console.log(
new Array(depth + 1).join('----'),
`[${node.kind}]`,
@@ -62,8 +66,4 @@ export abstract class AbstractAstParser {
node.getChildren(sourceFile).forEach(childNode => this._printAllChildren(sourceFile, childNode, depth));
}
protected _syntaxKindToName(kind: ts.SyntaxKind) {
return ts.SyntaxKind[kind];
}
}

View File

@@ -15,10 +15,10 @@ export class PipeParser extends AbstractTemplateParser implements ParserInterfac
protected _parseTemplate(template: string): TranslationCollection {
let collection: TranslationCollection = new TranslationCollection();
const regExp: RegExp = /(['"`])([^>\1\r\n]*?)\1\s*\|\s*translate/g;
const regExp: RegExp = /(['"`])((?:(?!\1).|\\\1)+)\1\s*\|\s*translate/g;
let matches: RegExpExecArray;
while (matches = regExp.exec(template)) {
collection = collection.add(matches[2]);
collection = collection.add(matches[2].replace('\\\'', '\''));
}
return collection;

View File

@@ -1,6 +1,6 @@
export interface TranslationType {
[key: string]: string
};
}
export class TranslationCollection {

View File

@@ -1,5 +1,3 @@
import * as ts from 'typescript';
export function _(key: string | string[]): string | string[] {
return key;
}

View File

@@ -18,6 +18,12 @@ describe('PipeParser', () => {
expect(keys).to.deep.equal(['SomeKey_NotWorking']);
});
it('should extract string using pipe, but between quotes only', () => {
const contents = `<input class="form-control" type="text" placeholder="{{'user.settings.form.phone.placeholder' | translate}}" [formControl]="settingsForm.controls['phone']">`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['user.settings.form.phone.placeholder']);
});
it('should extract interpolated strings using translate pipe', () => {
const contents = `Hello {{ 'World' | translate }}`;
const keys = parser.extract(contents, templateFilename).keys();
@@ -25,7 +31,7 @@ describe('PipeParser', () => {
});
it('should extract strings with escaped quotes', () => {
const contents = `Hello {{ 'World\'s largest potato' | translate }}`;
const contents = `Hello {{ 'World\\'s largest potato' | translate }}`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal([`World's largest potato`]);
});