feat(compiler): add location note to extracted xliff2 files (#16791)

Add source location as a note tag as `<note category="location">path/to/file.ts:start_line[,end_line]</note>`.
`[,end_line]` part is optional and specified only if the end line is different from the start line.

Fixes  #16531
This commit is contained in:
Olivier Combe
2017-05-22 20:20:45 +02:00
committed by Chuck Jazdzewski
parent 85d4c4b82e
commit 08dfe91b95
4 changed files with 111 additions and 10 deletions

View File

@ -35,9 +35,9 @@ export class Xliff2 extends Serializer {
messages.forEach(message => {
const unit = new xml.Tag(_UNIT_TAG, {id: message.id});
const notes = new xml.Tag('notes');
if (message.description || message.meaning) {
const notes = new xml.Tag('notes');
if (message.description) {
notes.children.push(
new xml.CR(8),
@ -49,11 +49,18 @@ export class Xliff2 extends Serializer {
new xml.CR(8),
new xml.Tag('note', {category: 'meaning'}, [new xml.Text(message.meaning)]));
}
notes.children.push(new xml.CR(6));
unit.children.push(new xml.CR(6), notes);
}
message.sources.forEach((source: i18n.MessageSpan) => {
notes.children.push(new xml.CR(8), new xml.Tag('note', {category: 'location'}, [
new xml.Text(
`${source.filePath}:${source.startLine}${source.endLine !== source.startLine ? ',' + source.endLine : ''}`)
]));
});
notes.children.push(new xml.CR(6));
unit.children.push(new xml.CR(6), notes);
const segment = new xml.Tag('segment');
segment.children.push(
@ -367,4 +374,4 @@ function getTypeForTag(tag: string): string {
default:
return 'other';
}
}
}