diff --git a/packages/localize/src/tools/src/extract/translation_files/xliff1_translation_serializer.ts b/packages/localize/src/tools/src/extract/translation_files/xliff1_translation_serializer.ts index 8dd6f2085b..c44f8f9d21 100644 --- a/packages/localize/src/tools/src/extract/translation_files/xliff1_translation_serializer.ts +++ b/packages/localize/src/tools/src/extract/translation_files/xliff1_translation_serializer.ts @@ -32,7 +32,18 @@ export class Xliff1TranslationSerializer implements TranslationSerializer { const ids = new Set(); const xml = new XmlFile(); xml.startTag('xliff', {'version': '1.2', 'xmlns': 'urn:oasis:names:tc:xliff:document:1.2'}); - xml.startTag('file', {'source-language': this.sourceLocale, 'datatype': 'plaintext'}); + // NOTE: the `original` property is set to the legacy `ng2.template` value for backward + // compatibility. + // We could compute the file from the `message.location` property, but there could + // be multiple values for this in the collection of `messages`. In that case we would probably + // need to change the serializer to output a new `` element for each collection of + // messages that come from a particular original file, and the translation file parsers may not + // be able to cope with this. + xml.startTag('file', { + 'source-language': this.sourceLocale, + 'datatype': 'plaintext', + 'original': 'ng2.template', + }); xml.startTag('body'); for (const message of messages) { const id = this.getMessageId(message); diff --git a/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts b/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts index 234ceaf45e..4dd7e4f4a2 100644 --- a/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts +++ b/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts @@ -36,7 +36,13 @@ export class Xliff2TranslationSerializer implements TranslationSerializer { 'xmlns': 'urn:oasis:names:tc:xliff:document:2.0', 'srcLang': this.sourceLocale }); - xml.startTag('file'); + // NOTE: the `original` property is set to the legacy `ng.template` value for backward + // compatibility. + // We could compute the file from the `message.location` property, but there could + // be multiple values for this in the collection of `messages`. In that case we would probably + // need to change the serializer to output a new `` element for each collection of + // messages that come from a particular original file, and the translation file parsers may not + xml.startTag('file', {'id': 'ngi18n', 'original': 'ng.template'}); for (const message of messages) { const id = this.getMessageId(message); if (ids.has(id)) { diff --git a/packages/localize/src/tools/test/extract/integration/main_spec.ts b/packages/localize/src/tools/test/extract/integration/main_spec.ts index 72b9d1aa5f..3f69a2d22f 100644 --- a/packages/localize/src/tools/test/extract/integration/main_spec.ts +++ b/packages/localize/src/tools/test/extract/integration/main_spec.ts @@ -149,7 +149,7 @@ runInEachFileSystem(() => { expect(fs.readFile(outputPath)).toEqual([ ``, ``, - ` `, + ` `, ` `, ` `, ` Hello, !`, @@ -218,7 +218,7 @@ runInEachFileSystem(() => { expect(fs.readFile(outputPath)).toEqual([ ``, ``, - ` `, + ` `, ` `, ` `, ` Hello, !`, @@ -276,7 +276,7 @@ runInEachFileSystem(() => { expect(fs.readFile(outputPath)).toEqual([ ``, ``, - ` `, + ` `, ` `, ` `, ` Message in !`, diff --git a/packages/localize/src/tools/test/extract/translation_files/xliff1_translation_serializer_spec.ts b/packages/localize/src/tools/test/extract/translation_files/xliff1_translation_serializer_spec.ts index 31ff2d99c2..f421850a32 100644 --- a/packages/localize/src/tools/test/extract/translation_files/xliff1_translation_serializer_spec.ts +++ b/packages/localize/src/tools/test/extract/translation_files/xliff1_translation_serializer_spec.ts @@ -72,7 +72,7 @@ runInEachFileSystem(() => { expect(output).toEqual([ ``, ``, - ` `, + ` `, ` `, ` `, ``, - ` `, + ` `, ` `, ` `, ` file.ts:6`,