- (chore) update packages
- (refactor) use tsquery for querying AST - (feat) autodetect usage of marker function and remove --marker cli argument - (bugfix) extract strings when TranslateService is declared directly as a class parameter. Closes https://github.com/biesbjerg/ngx-translate-extract/issues/83 - (bugfix) handle split strings: marker('hello ' + 'world') is now extracted as a single string: 'hello world'
This commit is contained in:
@@ -224,6 +224,7 @@ describe('ServiceParser', () => {
|
||||
console.log(translations[variable]);
|
||||
});
|
||||
}
|
||||
}
|
||||
`;
|
||||
const keys = parser.extract(contents, componentFilename).keys();
|
||||
expect(keys).to.deep.equal(['yes']);
|
||||
@@ -263,4 +264,39 @@ describe('ServiceParser', () => {
|
||||
expect(keys).to.deep.equal(['Extract me!', 'Hello!']);
|
||||
});
|
||||
|
||||
it('should extract strings when TranslateService is declared as a property', () => {
|
||||
const contents = `
|
||||
export class MyComponent {
|
||||
protected translateService: TranslateService;
|
||||
public constructor() {
|
||||
this.translateService = new TranslateService();
|
||||
}
|
||||
public test() {
|
||||
this.translateService.instant('Hello World');
|
||||
}
|
||||
`;
|
||||
const keys = parser.extract(contents, componentFilename).keys();
|
||||
expect(keys).to.deep.equal(['Hello World']);
|
||||
});
|
||||
|
||||
it('should extract strings passed to TranslateServices methods only', () => {
|
||||
const contents = `
|
||||
export class AppComponent implements OnInit {
|
||||
constructor(protected config: Config, protected translateService: TranslateService) {}
|
||||
|
||||
public ngOnInit(): void {
|
||||
this.localizeBackButton();
|
||||
}
|
||||
|
||||
protected localizeBackButton(): void {
|
||||
this.translateService.onLangChange.subscribe((event: LangChangeEvent) => {
|
||||
this.config.set('backButtonText', this.translateService.instant('Back'));
|
||||
});
|
||||
}
|
||||
}
|
||||
`;
|
||||
const keys = parser.extract(contents, componentFilename).keys();
|
||||
expect(keys).to.deep.equal(['Back']);
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user