Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
5cef383f3b | ||
|
677d2a35ca | ||
|
262a89206d | ||
|
bcb4a9c069 | ||
|
5ad1fe6a18 | ||
|
bc5ce7e80d | ||
|
030ab145d6 |
@@ -82,6 +82,8 @@ Options:
|
|||||||
--output, -o Paths where you would like to save extracted
|
--output, -o Paths where you would like to save extracted
|
||||||
strings. You can use path expansion, glob patterns
|
strings. You can use path expansion, glob patterns
|
||||||
and multiple paths [array] [required]
|
and multiple paths [array] [required]
|
||||||
|
--marker, -m Extract strings passed to a marker function
|
||||||
|
[string] [default: false]
|
||||||
--format, -f Output format
|
--format, -f Output format
|
||||||
[string] [choices: "json", "namespaced-json", "pot"] [default: "json"]
|
[string] [choices: "json", "namespaced-json", "pot"] [default: "json"]
|
||||||
--format-indentation, --fi Output format indentation [string] [default: "\t"]
|
--format-indentation, --fi Output format indentation [string] [default: "\t"]
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@biesbjerg/ngx-translate-extract",
|
"name": "@biesbjerg/ngx-translate-extract",
|
||||||
"version": "2.2.0",
|
"version": "2.2.3",
|
||||||
"description": "Extract strings from projects using ngx-translate",
|
"description": "Extract strings from projects using ngx-translate",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
@@ -58,8 +58,8 @@
|
|||||||
"chai": "3.5.0",
|
"chai": "3.5.0",
|
||||||
"mocha": "3.2.0",
|
"mocha": "3.2.0",
|
||||||
"ts-node": "3.0.2",
|
"ts-node": "3.0.2",
|
||||||
"tslint": "4.5.1",
|
"tslint": "5.0.0",
|
||||||
"tslint-eslint-rules": "3.5.1",
|
"tslint-eslint-rules": "4.0.0",
|
||||||
"typescript": "2.2.2"
|
"typescript": "2.2.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@@ -104,7 +104,7 @@ export class ExtractTask implements TaskInterface {
|
|||||||
|
|
||||||
if (this._options.clean) {
|
if (this._options.clean) {
|
||||||
const collectionCount = processedCollection.count();
|
const collectionCount = processedCollection.count();
|
||||||
processedCollection = processedCollection.intersect(processedCollection);
|
processedCollection = processedCollection.intersect(collection);
|
||||||
const removeCount = collectionCount - processedCollection.count();
|
const removeCount = collectionCount - processedCollection.count();
|
||||||
if (removeCount > 0) {
|
if (removeCount > 0) {
|
||||||
this._out(chalk.dim('- removed %d obsolete strings'), removeCount);
|
this._out(chalk.dim('- removed %d obsolete strings'), removeCount);
|
||||||
|
@@ -48,7 +48,11 @@ export abstract class AbstractAstParser {
|
|||||||
}, initialValue);
|
}, 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(
|
console.log(
|
||||||
new Array(depth + 1).join('----'),
|
new Array(depth + 1).join('----'),
|
||||||
`[${node.kind}]`,
|
`[${node.kind}]`,
|
||||||
@@ -62,8 +66,4 @@ export abstract class AbstractAstParser {
|
|||||||
node.getChildren(sourceFile).forEach(childNode => this._printAllChildren(sourceFile, childNode, depth));
|
node.getChildren(sourceFile).forEach(childNode => this._printAllChildren(sourceFile, childNode, depth));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _syntaxKindToName(kind: ts.SyntaxKind) {
|
|
||||||
return ts.SyntaxKind[kind];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -15,10 +15,10 @@ export class PipeParser extends AbstractTemplateParser implements ParserInterfac
|
|||||||
protected _parseTemplate(template: string): TranslationCollection {
|
protected _parseTemplate(template: string): TranslationCollection {
|
||||||
let collection: TranslationCollection = new 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;
|
let matches: RegExpExecArray;
|
||||||
while (matches = regExp.exec(template)) {
|
while (matches = regExp.exec(template)) {
|
||||||
collection = collection.add(matches[2]);
|
collection = collection.add(matches[2].replace('\\\'', '\''));
|
||||||
}
|
}
|
||||||
|
|
||||||
return collection;
|
return collection;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
export interface TranslationType {
|
export interface TranslationType {
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
};
|
}
|
||||||
|
|
||||||
export class TranslationCollection {
|
export class TranslationCollection {
|
||||||
|
|
||||||
|
@@ -1,5 +1,3 @@
|
|||||||
import * as ts from 'typescript';
|
|
||||||
|
|
||||||
export function _(key: string | string[]): string | string[] {
|
export function _(key: string | string[]): string | string[] {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,12 @@ describe('PipeParser', () => {
|
|||||||
expect(keys).to.deep.equal(['SomeKey_NotWorking']);
|
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', () => {
|
it('should extract interpolated strings using translate pipe', () => {
|
||||||
const contents = `Hello {{ 'World' | translate }}`;
|
const contents = `Hello {{ 'World' | translate }}`;
|
||||||
const keys = parser.extract(contents, templateFilename).keys();
|
const keys = parser.extract(contents, templateFilename).keys();
|
||||||
@@ -25,7 +31,7 @@ describe('PipeParser', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should extract strings with escaped quotes', () => {
|
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();
|
const keys = parser.extract(contents, templateFilename).keys();
|
||||||
expect(keys).to.deep.equal([`World's largest potato`]);
|
expect(keys).to.deep.equal([`World's largest potato`]);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user