Support alternate ng2-translate attribute in DirectiveParser. Add more tests

This commit is contained in:
Kim Biesbjerg 2016-12-08 16:09:06 +01:00
parent ff93233f6b
commit e5f937d7f6
2 changed files with 19 additions and 3 deletions

View File

@ -22,7 +22,7 @@ export class DirectiveParser extends AbstractTemplateParser implements ParserInt
.addBack()
.each((i: number, element: CheerioElement) => {
const $element = $(element);
const attr = $element.attr('translate');
const attr = $element.attr('translate') || $element.attr('ng2-translate');
if (attr) {
results.push(attr);

View File

@ -80,10 +80,26 @@ describe('DirectiveParser', () => {
expect(messages).to.deep.equal(['Hello World']);
});
it('should extract when using alternate translate attribute', () => {
const contents = '<div ng2-translate>Hello World<div>';
it('should extract contents when no ng2-translate attribute value is provided', () => {
const contents = '<div ng2-translate>Hello World</div>';
const messages = parser.process(templateFilename, contents);
expect(messages).to.deep.equal(['Hello World']);
});
it('should extract ng2-translate attribute if provided', () => {
const contents = '<div ng2-translate="KEY">Hello World<div>';
const messages = parser.process(templateFilename, contents);
expect(messages).to.deep.equal(['KEY']);
});
it('should extract bound ng2-translate attribute as key if provided', () => {
const contents = `<div [ng2-translate]="'KEY'">Hello World<div>`;
const messages = parser.process(templateFilename, contents);
expect(messages).to.deep.equal(['KEY']);
});
});