Skip to content

Commit

Permalink
fix(compiler): assert xliff messages have translations
Browse files Browse the repository at this point in the history
fixes #12815
closes #12604
  • Loading branch information
vicb committed Nov 14, 2016
1 parent 9ed9ff4 commit 7908679
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion modules/@angular/compiler/src/i18n/serializers/xliff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ class XliffParser implements ml.Visitor {
this._addError(element, `Duplicated translations for msg ${id}`);
} else {
ml.visitAll(this, element.children, null);
this._mlNodesByMsgId[id] = this._unitMlNodes;
if (this._unitMlNodes) {
this._mlNodesByMsgId[id] = this._unitMlNodes;
} else {
this._addError(element, `Message ${id} misses a translation`);
}
}
}
break;
Expand Down
18 changes: 18 additions & 0 deletions modules/@angular/compiler/test/i18n/serializers/xliff_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ export function main(): void {
});

describe('structure errors', () => {
it('should throw when a trans-unit has no translation', () => {
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="missingtarget">
<source/>
</trans-unit>
</body>
</file>
</xliff>`;

expect(() => {
loadAsMap(XLIFF);
}).toThrowError(/Message missingtarget misses a translation/);
});


it('should throw when a trans-unit has no id attribute', () => {
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
Expand Down

0 comments on commit 7908679

Please sign in to comment.