Fix Pipe regex and add test
This commit is contained in:
parent
0a4d58c1fa
commit
9d87ff368c
@ -15,7 +15,7 @@ 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 = new RegExp(/(['"`])([^\1]*?)\1\s*\|\s*translate/, 'g');
|
const regExp = new RegExp(/(['"`])([^\1\r\n]*?)\1\s*\|\s*translate/, 'g');
|
||||||
|
|
||||||
let matches: RegExpExecArray;
|
let matches: RegExpExecArray;
|
||||||
while (matches = regExp.exec(template)) {
|
while (matches = regExp.exec(template)) {
|
||||||
|
@ -56,4 +56,31 @@ describe('PipeParser', () => {
|
|||||||
expect(keys).to.deep.equal(['Info', 'Loading...']);
|
expect(keys).to.deep.equal(['Info', 'Loading...']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should extract strings on same line', () => {
|
||||||
|
const contents = `<span [attr]="'Hello' | translate"></span><span [attr]="'World' | translate"></span>`;
|
||||||
|
const keys = parser.extract(contents, templateFilename).keys();
|
||||||
|
expect(keys).to.deep.equal(['Hello', 'World']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should extract strings from this template', () => {
|
||||||
|
const contents = `
|
||||||
|
<ion-list inset>
|
||||||
|
<ion-item>
|
||||||
|
<ion-icon item-left name="person" color="dark"></ion-icon>
|
||||||
|
<ion-input formControlName="name" type="text" [placeholder]="'Name' | translate"></ion-input>
|
||||||
|
</ion-item>
|
||||||
|
<ion-item>
|
||||||
|
<p color="danger" danger *ngFor="let error of form.get('name').getError('remote')">
|
||||||
|
{{ error }}
|
||||||
|
</p>
|
||||||
|
</ion-item>
|
||||||
|
</ion-list>
|
||||||
|
<div class="form-actions">
|
||||||
|
<button ion-button (click)="onSubmit()" color="secondary" block>{{ 'Create account' | translate }}</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
const keys = parser.extract(contents, templateFilename).keys();
|
||||||
|
expect(keys).to.deep.equal(['Name', 'Create account']);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user